by @CodingExample

How to Force react component to re-render

Home » react » How to Force react component to re-render

To force a react component to re-render we need to call this.forceUpdate() method.

Example:

class App extends React.Component {

  handleUpdate = () => {
    this.forceUpdate();
  };

  render() {
    return (
      <div>
        <h1>{Math.random()}</h1>
        <button onClick={this.handleUpdate}>Update</button>
      </div>
    );
  }
}