Getting the 'propTypes' is not defined no-undef
hi all ,
I created my react app using create-react-app . It works fine .
But I am getting the error message **Getting the 'propTypes' is not defined no-undef** , if i try to use propTypes and came to know that it is coz of the eslint 4.* , do anyone know whether this is issue resolved or not .
You have barely provided any details so it's hard to answer.
But installing a different version of ESLint into a project generated by CRA is not supported, if that's what you did. Otherwise we'll need an example project to investigate.
@gaearon i have not installed ESLint locally , it comes with the default create-react-app , i just did the following steps
install -g create-react-app -> this i have done globally so that i can create the App anywhere within my computer . Then i just created a new directory for eg let say Test - > within this i executed create-react-app $projectname
Then cd $projectname and npm start . I havent done anything other than the above .This is my code ` import React, { Component } from 'react'; import PropTypes from 'prop-types'; import './App.css';
class App extends Component { render() { return (
The App name is : {this.props.name}
The App id is : {this.props.id}
The App Details is : {this.props.Details}
The App object is : {this.props.object.obj1}
App.propTypes = { name: PropTypes.string, id: PropTypes.number, Details: PropTypes.string, object: propTypes.object }
App.defaultProps = { name: "React App", id: 25, Details: "This is my first App", object: { obj1: "This is obj one", obj2: "This is obj one", obj3: "This is obj one" } }
export default App; `
Then the error is legit. You have a line that says:
object: propTypes.object
but there is no propTypes. There's only PropTypes (capital "P") which you imported.
This is exactly what the error says: propTypes is not defined.
To fix, change it to:
object: PropTypes.object
@gaearon Thanks a lot mate .
Glad it helped! Let us know if you bump into more issues.