top | item 22997304

(no title)

abuldauskas | 5 years ago

I don't really understand how this approach breaks what you are describing.

All I'm saying is that instead of hooks API being imported from React at global scope it could be provided as inputs into the components directly. They would still exist in the function body as you put it.

discuss

order

frosted-flakes|5 years ago

Oh, I thought you meant that the hooks would be called there, which was one of the many alternative proposals made after hooks were announced.

In any case, it still wouldn't work because hooks are composable. You can create your own custom hooks outside of components which can be used as if it was one of the primitive hooks. That's not possible if the primitive hooks can't be accessed outside the component scope, unless they're passed in as parameters every time the custom hook is called (and that would be a right pain in the backside).