I'm setting up a new React with the help of: Create React App
However, I'm running into a linting issue. I'm receiving the following linting error 'PropTypes' is not defined. (no-undef)
.
Here is the code that is causing the issue:
import React, { Component } from 'react'; import PropTypes from 'prop-types'; class Routers extends Component { static propTypes = { history: PropTypes.object.isRequired }; ...
I tried playing around with the react/prop-types rule, but to no avail.
propTypes = { //// key is the name of the prop and // value is the PropType } export default Count; PropTypes are also objects with a key and a value pair where the 'key' is the name of the prop while the value represents the type or class by which they are defined.
Building a component library This means users of your library cannot depend on your TypeScript type definitions for props, reiterating the relevance of PropTypes. PropTypes is normal JavaScript code, which means validations will also be possible when your library is being used.
One of the most important things when building React application is to make sure that the components receive correct props. Passing wrong props leads to bugs and unexpected behavior, so it's a good idea to warn developers about this as early as possible.
PropTypes is deprecated since React 15.5.
Since react 15.5, PropTypes is included in a separate package, 'prop-types'. So this line will help
import PropTypes from 'prop-types'
You can read more here
According to this issue comment.
It appears to be because you have installed eslint 4.x
when you should just use the eslint version that is shipped with create-react-app. You should remove any eslint you have manually installed and use the one that comes with the repo.
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