Skip to content

Commit bb50440

Browse files
committed
Document unsafe events on the container
1 parent 5f40057 commit bb50440

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

versioned_docs/version-7.x/navigation-container.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,25 @@ const unsubscribe = navigationRef.addListener('options', (e) => {
285285
});
286286
```
287287

288+
##### `__unsafe_action__`
289+
290+
The event is triggered whenever a navigation action is dispatched, and before the state changes from the action have been applied:
291+
292+
```js
293+
const unsubscribe = navigationRef.addListener('__unsafe_action__', (e) => {
294+
// The action object that was dispatched
295+
console.log(e.data.action);
296+
297+
// Whether the action didn't result in any state changes
298+
console.log(e.data.noop);
299+
300+
// Stack trace of the action, only available in development
301+
console.log(e.data.stack);
302+
});
303+
```
304+
305+
It's only intended for debugging purposes and shouldn't be used for app logic.
306+
288307
## Props
289308

290309
### `initialState`

versioned_docs/version-8.x/navigation-container.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,47 @@ const unsubscribe = navigationRef.addListener('options', (e) => {
285285
});
286286
```
287287

288+
##### `__unsafe_action__`
289+
290+
The event is triggered whenever a navigation action is dispatched, and before the state changes from the action have been applied:
291+
292+
```js
293+
const unsubscribe = navigationRef.addListener('__unsafe_action__', (e) => {
294+
// The action object that was dispatched
295+
console.log(e.data.action);
296+
297+
// Whether the action didn't result in any state changes
298+
console.log(e.data.noop);
299+
300+
// Stack trace of the action, only available in development
301+
console.log(e.data.stack);
302+
});
303+
```
304+
305+
It's only intended for debugging purposes and shouldn't be used for app logic.
306+
307+
##### `__unsafe_event__`
308+
309+
The event is triggered whenever an event is emitted by a navigator, and after all listeners have been called:
310+
311+
```js
312+
const unsubscribe = navigationRef.addListener('__unsafe_event__', (e) => {
313+
// The type of the event that was emitted
314+
console.log(e.data.type);
315+
316+
// The data object passed when emitting the event
317+
console.log(e.data.data);
318+
319+
// The key of the target route which received the event
320+
console.log(e.data.target);
321+
322+
// Whether event.preventDefault() was called on this event
323+
console.log(e.data.defaultPrevented);
324+
});
325+
```
326+
327+
It's only intended for debugging purposes and shouldn't be used for app logic. To run app logic in response to an event, use the relevant navigator's [`listeners`](screen.md#listeners) prop or [`navigation.addListener`](navigation-object.md#addlistener).
328+
288329
## Props
289330

290331
### `initialState`

versioned_docs/version-8.x/upgrading-from-7.x.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,23 @@ function MyHeader() {
12791279

12801280
It renders a plain `View` on non-iPadOS platforms.
12811281

1282+
### Navigation container ref now supports `__unsafe_event__`
1283+
1284+
The navigation container ref now supports a `__unsafe_event__` event to listen for events emitted by navigators:
1285+
1286+
```js
1287+
const unsubscribe = navigationRef.addListener('__unsafe_event__', (e) => {
1288+
console.log(e.data.type);
1289+
console.log(e.data.data);
1290+
console.log(e.data.target);
1291+
console.log(e.data.defaultPrevented);
1292+
});
1293+
```
1294+
1295+
This event is only intended for debugging purposes and shouldn't be used for app logic.
1296+
1297+
See [NavigationContainer docs](navigation-container.md#__unsafe_event__) for more details.
1298+
12821299
### `useLogger` devtools now shows more information
12831300

12841301
Previously, the `useLogger` devtools only showed navigation actions. It now shows the following additional information:

0 commit comments

Comments
 (0)