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?
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.