M
M
mishapsv2015-08-12 14:36:29
JavaScript
mishapsv, 2015-08-12 14:36:29

Why doesn't React code work after some changes towards es6?

I tried to write in React using the examples here - it worked.
Now I tried to rewrite it a little closer to ES6 - it doesn't work.
Where did I mess up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Abdullaev, 2015-08-12
@mishapsv

It should be something like this
. The main problem is that getInitialState is replaced with a constructor and there is no autobinding in the ES6 syntax, so either use .bind(this) or arrow functions:

handleChange = (e) => {
    this.setState({val: e.target.value});
  }

  tick = () => {
    this.setState({
      first: new Date() - this.state.start
    });
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question