ReactJs: callback function not called in case of this.setState

As in this script, http://jsfiddle.net/69z2wepo/3535/ this.setState is called in componentWillMountwith a callback this.loadData. But a function is this.loadDatanever called a callback.

+4
source share
1 answer

I don't know how the internal components work here, but looking at the docs for setState()...

... you can provide an additional callback function, which is executed after completion setState, and the component is re-displayed.

... and documents for componentWillMount()...

setState , render() , .

... , , setState() render() .

, loadData componentDidMount(), :

componentWillMount() {
  // ...
  this.setState({loaded, data});
},

componentDidMount() {
  this.loadData();
},
+2

All Articles