react native cannot read property 'navigate' of undefined

I recently transitioned from native development to RN. I encountered a small problem when writing interface jumps. This is the case. A view is encapsulated. There is a button in the view. Clicking the button needs to jump to another interface, but there is no inside the view. The navigation bar controller reported this error. At this time, we have to find a way to put a navigation bar controller into this view. The definition inside the view is as follows:

props:{
  navigation: PropTypes.object
}

constructor(props){
  super(props);
  this.navigation = this.props.navigation;
}

In the call view interface

<CustomView navigation={this.props.navigation}/>

This step is to pass the navigation bar controller to the view, so that the view can click the internal button to jump, the next step can be used in the view

this.navigation.navigate('CustomPage')

Of course, if you do n’t use this method, you can add a click event attribute to the view and pass in a custom function from the outside.

Guess you like

Origin www.cnblogs.com/li-wei203/p/12674429.html