Hot Module Replacement(HMR) in React

How can I enable HMR in reactjs ? Do I need to change any webpack configurations?

import React from 'react';
import ReactDOM from 'react-dom';
import './app/layout/styles.css';
import App from './app/layout/App';

const rootEl = document.getElementById('root');

function render() {
  ReactDOM.render(<App />, rootEl);
}

if (module.hot) {
  module.hot.accept('./app/layout/App', function () {
    setTimeout(render);
  });
}

render();

Can you tell me what is the role of setTimeout in the code above?
I’m confused how actually hot module replacement works. Please help

Source: Ask Javascript Questions

LEAVE A COMMENT