W
W
webe2018-05-19 12:37:51
React
webe, 2018-05-19 12:37:51

How to make such a construct work (how to activate ES8)?

state = {}
what is it in general and how to make it work?
as I understand it, es8
has always used this.state , why now without this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Insolation, 2018-05-19
@webe

Anton Spirin Quote

this is a shorthand notation that can only be used with babel. Specifically, the transform-class-properties plugin. It is included in the stage-2, stage-1, stage-0 presses. So, if you use one of them, feel free to use it.
Recording:
class Parent extends Component {
  constructor(props) {
    super(props);

    this.state = {
      data: []
    };

    this.handler = this.handler.bind(this);
  }

  handler(e) {
    // do something
  }
}

Similar:
class Parent extends Component {
  state = {
    data: [],
  };

  handler = e => {
    // do something
  };
}

In React development, this is one of the standards.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question