How can I enable Hot Module Replacement(HMR) in react?

Viewed 3973

Does the create-react-app come with built-in support for HMR? I have seen react app reloads on changes. But that's not HMR. What webpack configuration I need to add to enable HMR. I read online about setting hot option in webpack-dev-serve to true. I'm confused about HMR in react.

After searching for a while I came across this

import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'

// Opt-in to Webpack hot module replacement
if (module.hot) module.hot.accept()

ReactDOM.render(
  <App />,
  document.getElementById('app')
)

Then it says to add HotModuleReplacementPlugin in webpack.config.js
Do I need to manually add it or it comes pre-added. Also I read that react uses ReactRefreshWebpackPlugin. I'm confused please help.

1 Answers
Related