Skip to content

'Is not defined' errors in counter example #2459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dimitri-a opened this issue Jun 19, 2017 · 3 comments
Closed

'Is not defined' errors in counter example #2459

dimitri-a opened this issue Jun 19, 2017 · 3 comments

Comments

@dimitri-a
Copy link

When I run npm start in the redux\examples\counter I get :

Failed to compile.

./src/components/Counter.js
Line 5: 'propTypes' is not defined no-undef
Line 11: 'incrementIfOdd' is not defined no-undef
Line 17: 'incrementAsync' is not defined no-undef

Any ideas?

@yaempioy
Copy link

  1. Add constructor code follow.
constructor (props) {
    super(props)
    this.incrementIfOdd = this.incrementIfOdd.bind(this)
    this.incrementAsync = this.incrementAsync.bind(this)
  }
  1. Change code function follow.
incrementIfOdd () {
    if (this.props.value % 2 !== 0) {
      this.props.onIncrement()
    }
  }

  incrementAsync () {
    setTimeout(this.props.onIncrement, 1000)
  }

@timdorr
Copy link
Member

timdorr commented Jun 20, 2017

A PR would be best to get this fixed.

@krizzu
Copy link
Contributor

krizzu commented Jun 21, 2017

Hey,

Also, to get rid of propTypes is not defined, we could add prop checking to a class, like this:

Counter.propTypes = {
  value: PropTypes.number.isRequired,
  onIncrement: PropTypes.func.isRequired,
  onDecrement: PropTypes.func.isRequired
}

I went ahead and sent a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants