0

Using: "@react-navigation/drawer": "^5.4.0", "@react-navigation/native": "^5.1.4",

App.js:

    import { createDrawerNavigator } from '@react-navigation/drawer';
    ...
    const Drawer = createDrawerNavigator();
    const DrawerRender = () => {
    return (
      <NavigationContainer>
        <Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
          <Drawer.Screen name="Home" component={Home} />
          <Drawer.Screen name="Screen1" component={Screen1} options={{unmountOnBlur: true, gestureEnabled: false}} />
          <Drawer.Screen name="Screen2" component={Screen2} options={{unmountOnBlur: true, gestureEnabled: false}} />
        </Drawer.Navigator>
      </NavigationContainer>
    );}

From Screen1:

    navigateToPage = page_id => {
      this.closeCommentScreen();
      this.reopenModal = true;
      this.props.navigation.navigate('Screen2', {'page_id': 'testing'});
    }

On Screen2:

    export default class Screen2 extends React.Component {

    constructor(props) {
       super(props);
    }
    componentDidMount() {
       let id = this.props.navigation.state.params.page_id
       ...

I tried printing "this.props.navigation" and it always returns empty dictionary {}, hence params is undefined.

What am I doing wrong?

4
  • Seems same like this Commented Apr 16, 2020 at 1:55
  • my this.props.navigation is empty. state.params will always be null Commented Apr 16, 2020 at 3:40
  • It does not work on both screens? Commented Apr 16, 2020 at 3:50
  • navigation.navigate works with no issue. When I try to access the params from Screen2, it errors out Commented Apr 16, 2020 at 5:10

2 Answers 2

5

It's this.props.route.params

See the upgrade guide https://reactnavigation.org/docs/upgrading-from-4.x#separate-route-prop

Sign up to request clarification or add additional context in comments.

Comments

0

first Screen

nav.setOptions({
                        headerRight: () => <Button
                            title='Add coin'
                            onPress={() => navigation.navigate('Crypto Information', {
                                params: { currentCoins: temp },
                            })}
                        >
                        </Button>,
                    });

Second Screen

const CryptoInformation = ({ _, route }) => {
const { params } = route.params

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.