Skip to content

Commit db770d4

Browse files
committed
Document __unsafe_event__ for 7.x
1 parent b91c645 commit db770d4

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,28 @@ const unsubscribe = navigationRef.addListener('__unsafe_action__', (e) => {
304304

305305
It's only intended for debugging purposes and shouldn't be used for app logic.
306306

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, [listen to the event on the navigator level](navigation-events.md#listening-to-events) instead.
328+
307329
## Props
308330

309331
### `initialState`

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,8 @@ const unsubscribe = navigationRef.addListener('__unsafe_event__', (e) => {
16111611

16121612
This event is only intended for debugging purposes and shouldn't be used for app logic.
16131613

1614+
This API has also been backported to React Navigation 7.
1615+
16141616
See [NavigationContainer docs](navigation-container.md#__unsafe_event__) for more details.
16151617

16161618
### `useLogger` devtools now shows more information

0 commit comments

Comments
 (0)