Open resolritter opened 5 years ago
This is expected - ReactHotLoader could not change "the past".
hooks
. We could not detect your change, even if we wanted to do it.For now, and nearest future, that how it would work, there is nothing I could do.
Could you not do a source comparison and if it differs reset the state? I did this in a hot loading setup previously and I liked it more than attempting to preserve state changes when source changed.
Usually was just upcomingComponent.constructor.toString() !== previousSource
or similar.
I could do it for classes
not for hooks
.
As long as they got released I could try to look for a proper hooks for hooks. Probably it should be quite easy to properly destruct the old hooks(changed ones) and let the new ones to spin up.
I write a babel plugin for react hooks, it wrap hooks component with react component, https://github.com/yoution/babel-plugin-react-hooks-hot-load
Description
Continuing from https://github.com/gaearon/react-hot-loader/issues/1166.
Using this webpack configuration
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.
I tried to mark hook components as cold, like this
It seems to correctly mark them as cold, but doesn't change the state.
Environment
React Hot Loader version: 4.6.3
Reproducible Demo
https://github.com/reaysawa/saga-react-kit