Skip to content

Commit 8634161

Browse files
committed
Save the initial route name in screen tracking example
1 parent e2d1aeb commit 8634161

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
.DS_Store
33
.docusaurus
4+
.history
45

56
build/
67
translated_docs/

static/examples/5.x/screen-tracking-for-analytics.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ function Settings({ navigation }) {
3535
);
3636
}
3737

38+
const Stack = createStackNavigator();
39+
3840
export default function App() {
3941
const routeNameRef = React.useRef();
4042
const navigationRef = React.useRef();
4143

42-
const Stack = createStackNavigator();
44+
React.useEffect(() => {
45+
const state = navigationRef.current.getRootState();
46+
47+
// Save the initial route name
48+
routeNameRef.current = getActiveRouteName(state);
49+
}, []);
4350

4451
return (
4552
<NavigationContainer

versioned_docs/version-5.x/screen-tracking.md

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ export default function App() {
3838
const routeNameRef = React.useRef();
3939
const navigationRef = React.useRef();
4040

41+
React.useEffect(() => {
42+
const state = navigationRef.current.getRootState();
43+
44+
// Save the initial route name
45+
routeNameRef.current = getActiveRouteName(state);
46+
}, []);
47+
4148
return (
4249
<NavigationContainer
4350
ref={navigationRef}

0 commit comments

Comments
 (0)