Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Auto capture screens in React Navigation application
onStateChange
NavigationContainer
Userpilot.screen
import { useRef } from 'react'; import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native'; import * as Userpilot from '@userpilot/react-native'; export default () => { const navigationRef = useNavigationContainerRef(); const routeNameRef = useRef(); return ( <NavigationContainer ref={navigationRef} onReady={() => { routeNameRef.current = navigationRef.getCurrentRoute().name; }} onStateChange={async () => { const previousRouteName = routeNameRef.current; const currentRouteName = navigationRef.getCurrentRoute().name; if (previousRouteName !== currentRouteName) { Userpilot.screen(currentRouteName); } // Save the current route name for later comparison routeNameRef.current = currentRouteName; }} > {/* ... */} </NavigationContainer> ); };
Was this page helpful?