My eslint is failing on the following line.
const id = this.props.match.params.personID;
How can I fix this. Setting a rule to ignore would be ok. Finding a fix would be better.
Error
severity: 'Error'
message: ''match' is missing in props validation (react/prop-types)'
at: '14,27'
source: 'eslint'
code: 'react/prop-types'
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.
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.
React JS has an inbuilt feature for validating props data type to make sure that values passed through props are valid. React components have a property called propTypes which is used to setup data type validation. Syntax: The syntax to use propTypes is shown below. class Component extends React.
Props are required in TypeScript In the prop-types package, all props are optional by default. To make a prop required, you will have to use . isRequired explicitly.
When you are checking your prop types you also have to verify the shape of match.
If you are using flow:
type Props = {
match: {
params: {
field1: number,
field2: string,
}
}
...
}
class Component extends React.Component<Props> {
...
}
If you aren't and are using PropTypes...
import PropTypes from 'prop-types';
class MyComponent extends React.Component {
...
}
MyComponent.propTypes = {
match: PropTypes.shape({
params: PropTypes.shape({
field1: PropTypes.number.isRequired
field2: PropTypes.string
})
}),
...
}
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