4 ms·
React has some knowledge of a given component through the use of `createElement` (or its JSX equivalents), so it's not even using global variables. https://rea
by ascagnel_ 8y ago
React has some knowledge of a given component through the use of `createElement` (or its JSX equivalents), so it's not even using global variables.
https://reactjs.org/docs/hooks-faq.html#how-does-react-associate-hook-calls-with-components https://reactjs.org/docs/hooks-faq.html#how-does-react-assoc...
The "memory cells" the FAQ mentions sounds awfully like a map structure where React uses some internal identifier generated on first render to map any state handlers. The only "magic" bit is that it relies on the order of the `use` calls to be the same every time.
- Illniyar 8y agoIt is a globally shared variable. Really either react notifies or registers the component to the module to exports useState, or more likely useState goes to some react internal api and retrieves the currently running component. It's as much a global variable as the singleton pattern.