How does it work?
-
-
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 -
Replying to @sebmck @dan_abramov
Ah nevermind, I understand. A sufficiently smart compiler (*cough cough*) could inline it instead of using string concat.
1 reply 0 retweets 4 likes -
-
-
Replying to @sebmck @dan_abramov
Is this what flirting looks like at Facebook?
1 reply 0 retweets 6 likes
Flirting is when I give you commit access
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 