1

I am using version 4 react navigation and particularly createBottomTabNavigator with createStackNavigator for each tab. For all implemented tabs, if I scroll away from my landing screen called home screen and return back to it, useEffect is not invoked. I do this with the use of navigation.navigate() to navigate to the home screen. I tried adding 'resetOnBlur' option and set it to true for the createBottomNavigator but it still does not blur and re focus such that useEffect can be invoked as per documentation when using navigation.navigate to reach a bottom navigator tab:

https://reactnavigation.org/docs/4.x/bottom-tab-navigator/

I want to do something on home screen load every time the user returns back to it by not tapping the bottom bar but when redirected through code with the use of navigator.navigate. How can I achieve this in. navigation version 4 ?

catBuddy
  • 367
  • 1
  • 3
  • 15
  • 4
    Does this answer your question? [useEffect not called in React Native when back to screen](https://stackoverflow.com/questions/60182942/useeffect-not-called-in-react-native-when-back-to-screen) – Abe May 31 '22 at 00:11

1 Answers1

1

You can use useFocusEffect of react-navigation, like below,

import {useFocusEffect} from '@react-navigation/native';
useFocusEffect(
    useCallback(() => {
      // Do your work
    }, []),
  );
Ashish Sahu
  • 388
  • 3
  • 16