Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update README.md
  • Loading branch information
EdmondChuiHW authored Apr 26, 2020
commit 6537709aebaaa904a640b511e08d3dcd8524c4e2
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,16 +684,8 @@ LibV8 itself is already [beyond version 7](https://github.com/cowboyd/libv8/rele
Hot Module Replacement is [possible with this gem](https://stackoverflow.com/a/54846330/193785) as it does just pass through to Webpacker. Please open an issue to let us know tips and tricks for it to add to the wiki.

Similar to `useContext`, you can pass the webpack context into `useHotReload` to enable hot reload:
```js
var myCustomContext = require.context("custom_components", true)
var ReactRailsUJS = require("react_ujs")
// use `custom_components/` for <%= react_component(...) %> calls
ReactRailsUJS.useHotReload(myCustomContext)
```

You must ensure
1. [react-hot-loader](https://github.com/gaearon/react-hot-loader) and [@hot-loader/react-dom](https://github.com/hot-loader/react-dom) are installed;
2. your webpack config has the following in dev:
1. install [react-hot-loader](https://github.com/gaearon/react-hot-loader) and [@hot-loader/react-dom](https://github.com/hot-loader/react-dom)
1. add the following to your webpack config in dev:
```js
{
module: {
Expand All @@ -711,6 +703,12 @@ You must ensure
},
}
```
1. in your entry file, usually where you call `ReactRailsUJS.useContext` already, call `useHotReload`:
```js
var ReactRailsUJS = require("react_ujs")
var myCustomContext = require.context("custom_components", true)
ReactRailsUJS.useHotReload(myCustomContext)
```

One caveat is that currently you [cannot Server-Side Render along with HMR](https://github.com/reactjs/react-rails/issues/925#issuecomment-415469572).

Expand Down