Im building a web application using react-router and material-ui. i recently notice that react hot loader has updated and ive some issues while using ho loader with material-ui. when ever i use it with react router the hot loader wont work for the children components. here is my code of index.js
import React from 'react';
import {render} from 'react-dom';
import { AppContainer } from 'react-hot-loader'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import { Router, Route, Link, browserHistory,IndexRoute } from 'react-router'
import injectTapEventPlugin from 'react-tap-event-plugin';
import routes from './routes';
injectTapEventPlugin();
const App = () => (
<MuiThemeProvider>
<Router history={browserHistory} routes={routes} />
</MuiThemeProvider>
);
render(<App/>,document.getElementById('app'));
if (module.hot) {
module.hot.accept('./components/App', () => {
const NextApp = require('./components/App').default;
render(
<AppContainer>
<MuiThemeProvider>
<NextApp/>
</MuiThemeProvider>
</AppContainer>
,
document.getElementById('app')
);
});
}
here my App Component
import React from 'react';
import Home from './Home';
import About from './About/AboutPage.react';
import NavigationBar from './navigation/navigationBar.react';
class App extends React.Component{
render(){
return(
<div>
<NavigationBar/>
{this.props.children}
</div>
);
}
}
export default App;
the routes file
import React from 'react';
import {render} from 'react-dom';
import { Router, Route, Link, browserHistory,IndexRoute } from 'react-router'
import App1 from './components/App';
import NavigationBar from './components/navigation/navigationBar.react';
import greetings from './components/Login/greetings';
export default (
<Route path="/" component={App1}>
<IndexRoute component={greetings}/>
</Route>
);
when ever i make any changes to the child components the browser console gives a warning saying
the following modules couldn't be hot updated: (Full reload needed)
This is usually because the modules which have changed (and their parents) do not know how to hot reload themselves. See http://webpack.github.io/docs/hot-module-replacement-with-webpack.html for more details.
Any particular reason why im getting this and how to resolve this issue?
Make sure you're also wrapping the initial render with the react-hot-loader's AppContainer component as well. Like this:
const App = () => (
<AppContainer>
<MuiThemeProvider>
<Router history={browserHistory} routes={routes} />
</MuiThemeProvider>
</AppContainer>
);
Also, i'm not seeing your webpack config so make sure you also include react-hot-loader/patch
for your very first entry like this for example:
entry: [
'react-hot-loader/patch',
`webpack-dev-server/client?http://localhost:${config.port}`,
'webpack/hot/only-dev-server',
'./src/index.jsx'
],
If you also have a .babelrc
file, make sure to include it as one of your plugins like this:
{
"presets": [
"react",
"es2015",
"stage-0"
],
"plugins": [
"react-hot-loader/babel",
"transform-decorators-legacy"
]
}