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

199
Visualizações
React Native: getting route params typeof string? have to use JSON.parse after navigation

in my app I use react native firebase notifications (fcm) I'm experiencing a very weird bug, after I click on background notification I navigate to a new screen, in this screen useEffect I check for route params type and I get 'string', because of this I have to first do a JSON.parse, the weird thing is before navigation code, in App.js, I check they type of notification data sent from the server and it's object.

So right after navigation object gets turned into string type and I have to do JSON.parse, I'd prefer to not have to do this...

App.js

const handleBackgroundNotificationClicked = (data) =>
    {
        let notifData = data.data;
        console.log('notifDataType',typeof notifData);
        //RETURNS OBJECT, AS IT SHOULD
         navigate('OrderList88888', { activeUser:data.user })
}

In the screen where I navigate to I'm using useEffect to check route params type and they return type 'string':

const route = useRoute();

    useEffect(() => {
      
      //THIS RETUTNS STRING (WHY WAS IT CONVERTED TO STRING?)
        console.log('routeParamsType',typeof route.params.activeUser);

        let obj = JSON.parse(route.params.activeUser);
        console.log('objType',typeof obj);
        //THIS RETURNS OBJECT AND NOW I CAN USE THIS DATA
        
        getById(obj.id);
        
    }, []);

I also can't deconstruct params object like I in other screens where I navigate with useNavigation object

const { activeUser} = useRoute().params;

I instead have to use

const route = useRoute()
route.params.activeUser

I fear this is maybe because I'm using a navigation ref (since you can't use useNavigation hook inside App.js and that's where I set my notification listeners...

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
    console.log('paramsType',typeof params);
//THIS ALSO RETURNS OBJECT
    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
  }
};

So why are my route params being converted to string type after navigating with navigationRef?

about 4 years ago · Juan Pablo Isaza
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