Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
React Native: TypeError: navigationRef.isReady is not a function. (In 'navigationRef.isReady()'

in my react-native app App.js I setup a listener for firebase notifications, I also setup navigation in order to navigate and get current name inside notif handler functions, however when my app mounts I get this error:

TypeError: navigationRef.isReady is not a function. (In 'navigationRef.isReady()', 'navigationRef.isReady' is undefined)
getCurrentRoute

In my App.js file

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>

In my RootNavigation file:

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;
    }
  };
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Documentation states to use createNavigationContainerRef vs React.createRef.

So it would be

export const navigationRef = createNavigationContainerRef();

from https://reactnavigation.org/docs/navigating-without-navigation-prop

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda