|
|
|
|
|
by imtringued
628 days ago
|
|
Hooks have very little to do with closures. The key aspect of hooks is that what you are doing is something like this: function(context) {
context.useState()
} Where context is a variable that stores all the hook related data, except in reality that variable is a hidden global variable and useState() accesses that variable internally. Yeah, they added hooks as global functions so that they look like a "cute" DSL. It saves you the effort to type c.useState instead of useState I guess. The above code is just for illustrative purposes to get the idea across, according to other commenters the internal implementation has changed from what I remember, but the principle is still the same. Global functions demand global state. |
|