gaearon / gaearon/react-hot-loader

Component using hooks only hot-reloads the JSX, not the hooks' state

Open
#1,167 4 comments 0 reactions 0 assignees View on GitHub
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

Hello {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.

![image](https://user-images.githubusercontent.com/17429390/51922662-3b7d2780-23c8-11e9-8702-46e0cd1180b0.png)

### 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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.