Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i pass eslint checking for this.props.navigation.navigate (react-navigation)?

Tags:

I am using eslint airbnb in my react native project. The eslint throw error linting if i didn't validate the props, especially the props from react-navigation.

props validation 1 How do i validate this using PropTypes?

I am trying to validate it like this:

IntroScreen.propTypes = {   navigation: PropTypes.shape({     navigate: PropTypes.func,   }), }; 

but still got error linting like this error lint 2

How do i pass the default props, and should i?

like image 379
dehamzah Avatar asked Oct 05 '17 06:10

dehamzah


People also ask

How do I get navigation state in react navigation?

Above json array will show you current state of navigation under routeName index i.e. Show activity on this post. Have you tried to define navigationOptions in your route object? You can also set navigationOptions to a callback that will be invoked with the navigation object.

How do you navigate in stack Navigator?

navigate ​ If the screen is not present, it'll push a new screen. For example, if you have a stack with the history Home > Profile > Settings and you call navigate(Profile) , the resulting screens will be Home > Profile as it goes back to Profile and removes the Settings screen.


1 Answers

I am fixing it by setting the navigation and navigate props to be required.

IntroScreen.propTypes = {   navigation: PropTypes.shape({     navigate: PropTypes.func.isRequired,   }).isRequired, }; 

eslint force us to provide default props to be set if we set the props to be optional. So if we set the props to be required, the eslint will not warn you again.

like image 177
dehamzah Avatar answered Oct 07 '22 16:10

dehamzah