React Navigation's introduction page suggests the use of the following destructuring assignment:
const { navigate } = this.props.navigation;
However, when I implemented React Navigation in my App, ESLint is complaining about this line describing these both errors:
'navigation' is missing in props validation (react/prop-types)
'navigation.navigation' is missing in props validation (react/prop-types)
Even though the app seems to be working as intended, how would it be possible to remove these error lines?
One option is to add the
propTypes
prop to the component.Example
Another option is to disable eslint for that page and rule. More info here
In case of navigation in ES5 use something like this:
in ES6 use this:
and
import PropTypes from 'prop-types';
Solution today (since object Proptype isn't accepted by default anymore):
React.PropTypes
has moved into theprop-types
package since React v15.5 (see Typechecking with PropTypes).It should be used instead of importing from
react-native
(the package can be added into the project vianpm install --save prop-types
oryarn add prop-types
).And the example code complying with "Component should be written as a pure function" rule as follows: