-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,21 @@ import App from './App'; | |
|
||
const rootEl = document.getElementById('root'); | ||
ReactDOM.render( | ||
<AppContainer component={App} />, | ||
<AppContainer> | ||
<App /> | ||
</AppContainer>, | ||
rootEl | ||
); | ||
|
||
if (module.hot) { | ||
This comment has been minimized.
Sorry, something went wrong.
tbranyen
|
||
module.hot.accept('./App', () => { | ||
// If you use Webpack 2 in ES modules mode, you can | ||
This comment has been minimized.
Sorry, something went wrong.
hammeiam
|
||
// use <App /> here rather than require() a <NextApp />. | ||
const NextApp = require('./App').default; | ||
ReactDOM.render( | ||
<AppContainer component={require('./App').default} />, | ||
<AppContainer> | ||
<NextApp /> | ||
</AppContainer>, | ||
rootEl | ||
); | ||
}); | ||
|
6 comments
on commit b52c727
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I have it setup as this, how do I create the section under if (module.hot) {} since I'm not requiring the file, the store and provider are in the same file.
ReactDOM.render((
<AppContainer>
<Provider store={store}>
<Assignments data={modules} />
</Provider>
</AppContainer>
), creationComponentContainer);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artivilla please read about module.hot.accept
at https://webpack.github.io/docs/hot-module-replacement.html
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably like this:
ReactDOM.render(
<AppContainer>
<Provider store={store}>
<Assignments data={modules} />
</Provider>
</AppContainer>,
creationComponentContainer
);
if (module.hot) {
module.hot.accept('./Assignments', () => {
// If you use Webpack 2 in ES modules mode, you can
// use <Assignments /> here rather than require() a <NextAssignments />.
const NextAssignments = require('./Assignments').default;
ReactDOM.render(
<AppContainer>
<Provider store={store}>
<NextAssignments data={modules} />
</Provider>
</AppContainer>,
creationComponentContainer
);
});
}
However it would be easier to create an App
component in a separate file that looks like
const store = ...
const modules = ...
export default App() {
return (
<Provider store={store}>
<Assignments data={modules} />
</Provider>
);
}
and then use the example code with App
just like it’s written in this boilerplate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon i'm using the the app component with react router and react-redux provider component, and i'm getting this warning, but it works, the hot replacement.
Provider.js:29 <Provider> does not support changing `store` on the fly. It is most likely that you see this error because you updated to Redux 2.x and React Redux 2.x which no longer hot reload reducers automatically. See https://github.com/reactjs/react-redux/releases/tag/v2.0.0 for the migration instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move store
into index.js
and pass it as a prop so it doesn’t get created on every HMR update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaearon thanks man, it worked like a charm, thanks again for your commitment to improve the development experience, much appreciated.
thanks.
Ok this is a newbie question, but should
react-hot-loader
be included as adevDependency
or adependecy
? A Google search has given me both approaches. Thanks