Search code examples
react-nativestack-navigator

I'm new to React-Native and i was trying to move from one screen to another after a button is clicked


Error i receive when i try to navigate to another screen

undefined is not an object (evaluating '_this.props.navigation.navigate')

You can find the whole project here:

https://snack.expo.io/@nadamabrouk/mobile-flash-cards


Solution

  • In DeckList.js you need to pass the navigation to the child prop

    {Object.values(entries).map((entry, index) => {
              return (
                <DeckDetail
                  navigation={this.props.navigation}
                  key={index}
                  entry={entry}
                />
              );
    })}
    

    and in the onPress handler it should be DeckView instead of Deckview

    onPress={() => this.props.navigation.navigate("DeckView")}