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

141
Visualizações
EXPO useEffect not called on navigating to same screen

I have one screen which called useEffect when rendered first time in the flow. The second time I navigate to the screen in the flow , use Effect is not called but I want to call a function upon first time before , after or during render function is called when we navigate a second time to the same screen.

Here is the navigate call for everytime navigating to this screen from various screens

navigation.navigate("x", { u:type, s:title});

The following is the structure for my screen. I am not using components but functions with navigation

const x = ({ navigation}) => {
    ...
   return (
    <View style={styles.a}>
            ...    
   </View>
  );
};

export default x;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The problem here is that a screen remains mounted in react-native after the initial navigation. Thus, a useEffect with an empty dependency array won't be called subsequently on navigation.

Notice that this behavior differs from the web.

If you are coming to react-navigation from a web background, you may assume that when user navigates from route A to route B, A will unmount (its componentWillUnmount is called) and A will mount again when user comes back to it. While these React lifecycle methods are still valid and are used in react-navigation, their usage differs from the web.

The recommended way to solve this is described here. For your case this can be solved as follows.

import { useFocusEffect } from '@react-navigation/native';

const x = ({ navigation}) => {
    
   useFocusEffect(
     React.useCallback(() => {
      // called when screen is focused, thus everytime on navigation
      return () => {
        // unfocus... cleanup ... or whatever
      };
    }, [])
  );

   ...

   return (
    <View style={styles.a}>
            ...    
   </View>
  );
};

export default x;
about 4 years ago · Juan Pablo Isaza Relatório

0

useEffect will be called on first load of your functional component or when some dependency will be changed. Everything remains the same, so your useEffect will not work. Consider using useFocusEffect from react-navigation lib instead.

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