Skip to content

Commit

Permalink
Wrap root component in root.js not app.js so hot reloading can work
Browse files Browse the repository at this point in the history
React-hot-loader v3 requires all sub components to be required in a
different file.
  • Loading branch information
KyleAMathews committed Oct 31, 2016
1 parent 2d2c048 commit 36f2c16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 2 additions & 6 deletions lib/intermediate-representation-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ const rootElement = document.getElementById(`react-mount`)
let Root = require('./root')
if (Root.default) { Root = Root.default }

// Let site, plugins wrap the site e.g. for Redux.
const WrappedRoot = apiRunner('wrapRootComponent', { Root: Root }, Root)
ReactDOM.render(
<HotContainer>
<WrappedRoot />
<Root />
</HotContainer>,
rootElement
)
Expand All @@ -23,11 +21,9 @@ if (module.hot) {
module.hot.accept(`./root`, () => {
let NextRoot = require('./root')
if (NextRoot.default) { NextRoot = NextRoot.default }
// Let site, plugins wrap the site e.g. for Redux.
const WrappedRoot = apiRunner('wrapRootComponent', { Root: NextRoot }, NextRoot)
ReactDOM.render(
<HotContainer>
<WrappedRoot />
<NextRoot />
</HotContainer>,
rootElement
)
Expand Down
5 changes: 4 additions & 1 deletion lib/intermediate-representation-dir/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ const Root = () => (
/>
)

export default Root
// Let site, plugins wrap the site e.g. for Redux.
const WrappedRoot = apiRunner('wrapRootComponent', { Root: Root }, Root)

export default WrappedRoot

0 comments on commit 36f2c16

Please sign in to comment.