Why should we put parameter into module.hot.accept()
? If we put nothing, webpack.HotModuleReplacementPlugin
works, but also React component will lose its state data.
If we use react-hot-loader
, we should put parameters to accept
method, but I don't know what the first parameter means, and also why the
callback should require
again and get the default
?
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {AppContainer} from 'react-hot-loader';
import getRouter from './src/router';
const boot = (elements)=> {
ReactDOM.render(
<AppContainer>
{elements}
</AppContainer>
, document.getElementById('app'));
}
let rs = getRouter();
boot(rs); //first render
// render after source code change
if (module.hot) {
module.hot.accept('./src/router', ()=> {
boot(require('./src/router').default())
});
}