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?
To fix ESLint error missing in props validation with React, we can add a comment or disable the rule globally with a config. to disable prop type check for the line immediately below the comment in our code. in . eslintrc to disable the prop type validation rule for the whole project.
To fix the 'React eslint error missing in props validation' when developing a React app, we can set the prop types of the props in the component causing the error. to import the prop-types package to let us add prop type validation to the Foo component.
React Navigation does not include support for the peek & pop feature available on devices with 3D touch.
React Navigation library is one of the most used navigation libraries in the React Native ecosystem. It is written in TypeScript, and you can create React components and apply any navigation patterns from Stack, Tab, and Drawer.
React.PropTypes
has moved into the prop-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 via npm install --save prop-types
or yarn add prop-types
).
And the example code complying with "Component should be written as a pure function" rule as follows:
// In addition to other imports:
import PropTypes from 'prop-types';
const LoginScreen = ({ navigation }) => (
<View>
<Button
title="Login"
onPress={() => navigation.navigate('MainScreen')}
/>
</View>
);
LoginScreen.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
};
Solution today (since object Proptype isn't accepted by default anymore):
export default class LoginScreen extends Component {
static propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func.isRequired,
}).isRequired,
}
}
One option is to add the propTypes
prop to the component.
Example
LoginScreen.propTypes = {
navigation: PropTypes.object.isRequired,
};
Another option is to disable eslint for that page and rule. More info here
Rule Options
This rule can take one argument to ignore some specific props during validation.
... "react/prop-types": [<enabled>, { ignore: <ignore>, customValidators: <customValidator> }] ...
When Project needs navigation to almost all componenets. We can also silence the linting for that specific prop.
By adding the following in the eslint configuration:
"rules": {
"react/prop-types": ["error", { "ignore": ["navigation"] }]
}
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