en mi aplicación nativa de reacción App.js, configuro un oyente para las notificaciones de Firebase, también configuro la navegación para navegar y obtener el nombre actual dentro de las funciones del controlador de notificación, sin embargo, cuando mi aplicación se monta, aparece este error:
TypeError: navigationRef.isReady is not a function. (In 'navigationRef.isReady()', 'navigationRef.isReady' is undefined) getCurrentRouteEn mi archivo App.js
import { navigationRef, isReadyRef, getCurrentRoute, navigate } from '@env/RootNavigation.js'; useEffect(() => { console.log('APP STARTED'); registerListener(); }, []); const registerListener = () => { messaging().onMessage((message) => { handleForegroundNotification(message); }); }; const handleForegroundNotification = (message) => { let routeName = getCurrentRoute(); Alert.alert(routeName); }; <NavigationContainer ref={navigationRef} onReady={ () => { isReadyRef.current = true; } }> <ROOTSTACK1></ROOTSTACK1> </NavigationContainer>En mi archivo RootNavigation:
import * as React from 'react'; export const isReadyRef = React.createRef(); export const navigationRef = React.createRef(); export function navigate(name, params) { if (isReadyRef.current && navigationRef.current) { // Perform navigation if the app has mounted navigationRef.current.navigate(name, params); } else { // You can decide what to do if the app hasn't mounted // You can ignore this, or add these actions to a queue you can call later } }; export function getCurrentRoute(){ if (navigationRef.isReady()) { const route=navigationRef.getCurrentRoute(); console.log(route); // sample output {key:"Home-k2PN5aWMZSKq-6TnLUQNE",name:"Home"} return route.name; } };Los estados de documentación para usar createNavigationContainerRef vs React.createRef.
asi seria
export const navigationRef = createNavigationContainerRef();de https://reactnavigation.org/docs/navigating-without-navigation-prop