Skip to content

Commit 7b71b70

Browse files
committed
Document logger devtool
1 parent 6c92221 commit 7b71b70

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

static/assets/7.x/devtool-logger.mp4

356 KB
Binary file not shown.

versioned_docs/version-7.x/devtools.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,67 @@ Hooks from this package only work during development and are disabled in product
2121

2222
The package exposes the following APIs:
2323

24+
### `useLogger`
25+
26+
This hook provides a logger for React Navigation. It logs the navigation state and actions to the console.
27+
28+
<video playsInline autoPlay muted loop style={{ width: "585px" }}>
29+
30+
<source src="/assets/7.x/devtool-logger.mp4" />
31+
</video>
32+
33+
**Usage:**
34+
35+
To use the hook, import it and pass a `ref` to the `NavigationContainer` as its argument:
36+
37+
<Tabs groupId="config" queryString="config">
38+
<TabItem value="static" label="Static" default>
39+
40+
```js
41+
import * as React from 'react';
42+
import {
43+
createStaticNavigation,
44+
useNavigationContainerRef,
45+
} from '@react-navigation/native';
46+
import { useLogger } from '@react-navigation/devtools';
47+
48+
/* content */
49+
50+
export default function App() {
51+
const navigationRef = useNavigationContainerRef();
52+
53+
useLogger(navigationRef);
54+
55+
return <Navigation ref={navigationRef} />;
56+
}
57+
```
58+
59+
</TabItem>
60+
61+
<TabItem value="dynamic" label="Dynamic">
62+
63+
```js
64+
import * as React from 'react';
65+
import {
66+
NavigationContainer,
67+
useNavigationContainerRef,
68+
} from '@react-navigation/native';
69+
import { useLogger } from '@react-navigation/devtools';
70+
71+
export default function App() {
72+
const navigationRef = useNavigationContainerRef();
73+
74+
useLogger(navigationRef);
75+
76+
return (
77+
<NavigationContainer ref={navigationRef}>{/* ... */}</NavigationContainer>
78+
);
79+
}
80+
```
81+
82+
</TabItem>
83+
</Tabs>
84+
2485
### `useReduxDevToolsExtension`
2586

2687
This hook provides integration with [Redux DevTools Extension](https://github.com/reduxjs/redux-devtools). It also works with [`React Native Debugger app`](https://github.com/jhen0409/react-native-debugger) which includes this extension.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,11 @@ Previously, we added a Flipper plugin for React Navigation to make debugging nav
367367
368368
Since the React Native team migrating away from Flipper, it doesn't make much sense for us to spend additional resources to keep supporting it. So we've removed the Flipper plugin from `@react-navigation/devtools`.
369369

370-
As an alternative, you can use [React Navigation devtools plugin for Expo](https://docs.expo.dev/debugging/devtools-plugins/#react-navigation) if you are using [Expo](https://expo.dev).
370+
Alternatively, you can use the following developer tools:
371+
372+
- [Logger](devtools.md#uselogger)
373+
- [Integration for Redux DevTools Extension](devtools.md#usereduxdevtoolsextension)
374+
- [Devtools plugin for Expo](https://docs.expo.dev/debugging/devtools-plugins/#react-navigation) if you are using [Expo](https://expo.dev).
371375

372376
#### Various deprecated APIs are removed
373377

@@ -878,3 +882,9 @@ npm install react-native-drawer-layout
878882
```
879883

880884
See [`react-native-drawer-layout`](drawer-layout.md) for usage.
885+
886+
### `useLogger` devtool
887+
888+
The `@react-navigation/devtools` package now exports a `useLogger` hook. It can be used to log navigation actions to the console:
889+
890+
See [`useLogger`](devtools.md#uselogger) for usage.

0 commit comments

Comments
 (0)