Ask HN: Can someone explain me React Hooks?
I find React hooks complex and hard to gasp. They feel too smart and over-engineered. When I write JavaScript I tend to think of simple functions with normal programming constructs. I'd rather use basic variables (on instances, localStorage, URL, etc..) rather than a weird beast like `useState(0)`. What is going on here? Am I stupid or something?
(
2 comments
| on HN
)
I'd suggest reading these couple articles to understand more about the "how they work" and "how they're designed" aspects:
- https://www.swyx.io/hooks/
- https://overreacted.io/why-isnt-x-a-hook/
- https://overreacted.io/react-as-a-ui-runtime/
When react executes your component function, it will initialize a context (a big array) and each hook will be linked to an index in this context.
So, while being nearly pure, we can describe side effect but only for the provided context.