GeekyAnts / native-base-react-navigation-stack-navigator

126 stars 124 forks source link

Passing params gives undefined #1

Closed aizulhussin closed 6 years ago

aizulhussin commented 7 years ago

Hi, i tried passing a parameter in LucyChat.js

<Button
            rounded
            danger
            style={{ marginTop: 20, alignSelf: "center" }}
            onPress={() => navigate("Profile",{id:'Lucy'})}
          >

However when i print the log in Profile.js, it gives undefined error

console.log("ID:",this.props.navigation.state.params.id);

Jasbir23 commented 7 years ago

@aizulhussin , Nesting Navigator components is indeed creating problems with passing params. Found some issues in React Navigation related to this problem. Some of these include #80, #1251, #1237 I tried to find a workaround this. Navigating something like this helps us pass params successfully.

const navigationAction = NavigationActions.navigate({
                routeName: "ProfileScreen", // <==== this is parent Profile tabNavigator
                action: NavigationActions.navigate({
                  routeName: "Profile", // <===== this is default child Screen for Profile tabNavigator
                  params: { name: "JADE" }
                })
              });
this.props.navigation.dispatch(navigationAction);

However this appends two components for the same Profile screen on the navigation stack. Please add any other input that might help solve this. Thanks