Experimenting with hot reloading again. Found an approach that seems to work well for hot reloading Hooks. Would require some tweaks in React though.pic.twitter.com/2WueEBfkT1
-
Show this thread
-
Note an interesting moment: when I added second state to SearchResults, it correctly inferred the order of Hooks changed, and so it remounted my component.
6 replies 0 retweets 77 likesShow this thread -
-
Replying to @sebmck
Build-time plugin composes a signature for each component. A signature contains each use* call in component body with: 1. its name 2. stringified LHS of how its result is used It also composes signatures of every custom Hook inside. (Each is defined with same mechanism.)
2 replies 0 retweets 6 likes -
Replying to @dan_abramov @sebmck
Something like this for final example: useHNSearch.__signature__ = 'useState{const [data, setData]} useEffect'; SearchResults.__signature__ = 'useState{const [page, setPage]} useHNSearch{const data}' + '!' + useHNSearch.__signature__;
1 reply 0 retweets 5 likes -
Replying to @dan_abramov @sebmck
As long as you don't break other rules this should be sufficient to detect adding/removing/reordering Hooks, even inside other custom Hooks
1 reply 0 retweets 4 likes -
Replying to @dan_abramov @sebmck
There are some corner cases like when there's no LHS, e.g. useState(useContext(Foo)), or when custom Hook is in TDZ so can’t reference it eagerly, so will need to work it out a little. But getting common cases right is usually good enough.
1 reply 0 retweets 1 like -
Replying to @dan_abramov
No LHS could use the statement/expression position, with some offsets. What do you mean by a custom hook in TDZ?
1 reply 0 retweets 0 likes
Ah nevermind, I understand. A sufficiently smart compiler (*cough cough*) could inline it instead of using string concat.
-
-
-
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 