import React from 'react'; import ReactDOM from 'react-dom'; class App extends React.Component { constructor() { super(); this.state = { data: [] } this.setStateHandler = this.setStateHandler.bind(this); this.forceUpdateHandler = this.forceUpdateHandler.bind(this); }; setStateHandler() { var item = "setState..." var myArray = this.state.data.slice(); myArray.push(item); this.setState({data: myArray}) }; forceUpdateHandler() { this.state.data = []; this.forceUpdate(); }; render() { return ( <div> <button onClick = {this.setStateHandler}>setState</button> <button onClick = {this.forceUpdateHandler}>foreceUpdate</button> <h4>State Array: {this.state.data}</h4> </div> ); } } ReactDOM.render(<App />, document.getElementById('root'));