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
.
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
How do i pass the default props, and should i?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With