14
15
```js
16
if (process.env.NODE_ENV !== 'production') {
17
- const { connectToDevTools } = require("react-devtools-core");
17
+ const { initialize, connectToDevTools } = require("react-devtools-core");
18
19
+ initialize(settings);
20
// Must be called before packages like react or react-native are imported
20
- connectToDevTools({
21
- ...config
22
- });
21
+ connectToDevTools({...config});
22
}
23
```
24
25
> **NOTE** that this API (`connectToDevTools`) must be (1) run in the same context as React and (2) must be called before React packages are imported (e.g. `react`, `react-dom`, `react-native`).
26
27
+### `initialize` arguments
28
+| Argument | Description |
29
+|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
30
+| `settings` | Optional. If not specified, or received as null, then default settings are used. Can be plain object or a Promise that resolves with the [plain settings object](#Settings). If Promise rejects, the console will not be patched and some console features from React DevTools will not work. |
31
+
32
+#### `Settings`
33
+| Spec | Default value |
34
+|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
35
+| <pre>{<br> appendComponentStack: boolean,<br> breakOnConsoleErrors: boolean,<br> showInlineWarningsAndErrors: boolean,<br> hideConsoleLogsInStrictMode: boolean<br>}</pre> | <pre>{<br> appendComponentStack: true,<br> breakOnConsoleErrors: false,<br> showInlineWarningsAndErrors: true,<br> hideConsoleLogsInStrictMode: false<br>}</pre> |
36
+
37
### `connectToDevTools` options
29
-| Prop | Default | Description |
30
-|---|---|---|
31
-| `host` | `"localhost"` | Socket connection to frontend should use this host. |
32
-| `isAppActive` | | (Optional) function that returns true/false, telling DevTools when it's ready to connect to React. |
33
-| `port` | `8097` | Socket connection to frontend should use this port. |
34
-| `resolveRNStyle` | | (Optional) function that accepts a key (number) and returns a style (object); used by React Native. |
35
-| `retryConnectionDelay` | `200` | Delay (ms) to wait between retrying a failed Websocket connection |
36
-| `useHttps` | `false` | Socket connection to frontend should use secure protocol (wss). |
37
-| `websocket` | | Custom `WebSocket` connection to frontend; overrides `host` and `port` settings. |
38
+| Prop | Default | Description |
39
+|------------------------|---------------|---------------------------------------------------------------------------------------------------------------------------|
40
+| `host` | `"localhost"` | Socket connection to frontend should use this host. |
41
+| `isAppActive` | | (Optional) function that returns true/false, telling DevTools when it's ready to connect to React. |
42
+| `port` | `8097` | Socket connection to frontend should use this port. |
43
+| `resolveRNStyle` | | (Optional) function that accepts a key (number) and returns a style (object); used by React Native. |
44
+| `retryConnectionDelay` | `200` | Delay (ms) to wait between retrying a failed Websocket connection |
45
+| `useHttps` | `false` | Socket connection to frontend should use secure protocol (wss). |
46
+| `websocket` | | Custom `WebSocket` connection to frontend; overrides `host` and `port` settings. |
47
+| `onSettingsUpdated` | | A callback that will be called when the user updates the settings in the UI. You can use it for persisting user settings. | |
48
49
50
### `connectWithCustomMessagingProtocol` options
41
-| Prop | Description |
42
-|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
43
-| `onSubscribe` | Function, which receives listener (function, with a single argument) as an argument. Called when backend subscribes to messages from the other end (frontend). |
44
-| `onUnsubscribe` | Function, which receives listener (function) as an argument. Called when backend unsubscribes to messages from the other end (frontend). |
45
-| `onMessage` | Function, which receives 2 arguments: event (string) and payload (any). Called when backend emits a message, which should be sent to the frontend. |
51
+| Prop | Description |
52
+|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
53
+| `onSubscribe` | Function, which receives listener (function, with a single argument) as an argument. Called when backend subscribes to messages from the other end (frontend). |
54
+| `onUnsubscribe` | Function, which receives listener (function) as an argument. Called when backend unsubscribes to messages from the other end (frontend). |
55
+| `onMessage` | Function, which receives 2 arguments: event (string) and payload (any). Called when backend emits a message, which should be sent to the frontend. |
56
+| `onSettingsUpdated` | A callback that will be called when the user updates the settings in the UI. You can use it for persisting user settings. |
57
58
Unlike `connectToDevTools`, `connectWithCustomMessagingProtocol` returns a callback, which can be used for unsubscribing the backend from the global DevTools hook.
59