gaearon / gaearon/react-hot-loader
Component using hooks only hot-reloads the JSX, not the hooks' state
- Dominant language
- JavaScript
- Stars
- 12.2k
- Forks
- 775
- PR merge metrics
- No merged PRs in 30d
Description
### Description
Continuing from https://github.com/gaearon/react-hot-loader/issues/1166.
Using this webpack configuration
```
rules: [
{
test: /\.jsx?$/,
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: true
}
},
"react-hot-loader/webpack"
]
},
```
`React-Hot-Loader: react-🔥-dom patch detected. You may use all the features.`
My component using hooks updates if I change the rendered content (what is returned), but **not if I change the hooks' state itself**.
```
function HelloReact() {
// 🔴 Changing state does NOT hot-reload the message
// 👇
const [message, setMessage] = useState('Niels')
return (
// Changing div or Hello hot-reloads the component but NOT the message
);
}
```
---
I tried to mark hook components as cold, like this
```
onComponentCreate: (type, name) => {
if (!String(type).startsWith('function AppContainer()') && String(type).match(/use/)) {
console.log(type)
}
return (!String(type).startsWith('function AppContainer()') && String(type).match(/use/)) ? cold(type) : type
}
```
It seems to correctly mark them as cold, but doesn't change the state.

### Environment
React Hot Loader version: 4.6.3
1. Operating system: Ubuntu Linux
2. Browser: Chrome
### Reproducible Demo
https://github.com/reaysawa/saga-react-kit
Contributor guide
Assessment
This issue has not been assessed yet.