HACKER Q&A
📣 tipiirai

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?


  👤 acemarke Accepted Answer ✓
Are you asking more about how hooks work internally, how to use them, or why they're designed this way?

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/


👤 Isammoc
The whole purpose is the pureness of your component.

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.