3

I am following the Redux Github repo's example/todomvc and encountered the following issue:

[eslint] 'propTypes' is not defined. (no-undef)

The code related to this issue,

export default class Header extends Component {
  static propTypes = {
    addTodo: PropTypes.func.isRequired
  }

 handleSave = text => {
  if (text.length !== 0) {
    this.props.addTodo(text)
  }
}

To reproduce the error, just

cd example/todomvc npm install npm start

And the program would be interrupted caused by compile error.

It seems to be a long unresolved issue related to create-react-app, I've read this post which claimed to resolve the issue by changing eslint version to 3.19.0. However, create-react-app did ship with eslint@3.19.0, no need to change its version.

So what's the proper way to correct this issue ? It could be possible to:

  1. change static property by using Header.propTypes instead of static syntax

However that doesn't resolve the issue.

Sven
  • 31
  • 2
  • 2
    Do you have `import PropTypes from 'prop-types';` at the top of your file? – Kyle Richardson Dec 19 '17 at 02:32
  • Hi Kyle, thanks for the reply. Yes, `prop-types` is imported, in fact, I happened to see this [issue](https://github.com/babel/babel-eslint/issues/312) which clarifies that class static property could be parsed by `babel-eslint`@KyleRichardson – Sven Dec 20 '17 at 23:01

0 Answers0