Search code examples
javascriptreact-nativereact-native-navigation

React-Native-Navigation, how to refresh a route when navigating to it via navigation.navigate("routename", {randomparams})


I have a bottomTabNavigator which has two stacknavigators. Each stacknavigator has their own respective screens within them. Whenever I use something like

navigator.navigate("Stackname" {screen:"screenname", randomProp: "seomthing")

the params are sent to the stacknavigator, and not the screen itself. I kinda got past the issue by passing in

initialParams=route.params

within the stacknavigators, but they won't refresh when I call the first block of code for a second time. Any ideas?


Solution

  • Instead of:

    navigator.navigate("StackName" {screen:"screenName", paramPropKey: "paramPropValue");
    

    Use this:

    navigator.navigate("screenName", {'paramPropKey': 'paramPropValue'});
    

    In screenName:

    export default ({route}) => {
       useEffect(() => {
          // do something
       }, [route]);
    };