Reactjs higher order component to easily avoid the unsafe setState
$ npm install with-safe-set-state
import React, { Component } from 'react';
import { withSafeSetState } from 'with-safe-set-state';
class Box extends Component {
constructor() {
super();
this.state = { info: 'Default' };
}
_onClick() {
setTimeout(() => {
this.setState(_ => ({
info: 'OK'
}));
}, 1000);
}
render() {
return <button onClick={this._onClick.bind(this)}>Click</button>;
}
}
export default withSafeSetState(Box);
MIT © Whien