You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: expose installHook with settings argument from react-devtools-core/backend (#30987)
Stacked on #30986.
Previously, we would call `installHook` at a top level of the JavaScript
module. Because of this, having `require` statement for
`react-devtools-core` package was enough to initialize the React
DevTools global hook on the `window`.
Now, the Hook can actually receive an argument - initial user settings
for console patching. We expose this as a function `initialize`, which
can be used by third parties (including React Native) to provide the
persisted settings.
The README was also updated to reflect the changes.
// Must be called before packages like react or react-native are imported
20
-
connectToDevTools({
21
-
...config
22
-
});
21
+
connectToDevTools({...config});
23
22
}
24
23
```
25
24
26
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`).
|`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. |
|`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. |
|`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. |
46
57
47
58
Unlike `connectToDevTools`, `connectWithCustomMessagingProtocol` returns a callback, which can be used for unsubscribing the backend from the global DevTools hook.
0 commit comments