2 ms·
This is my understanding, but I just use hooks, don't know the implementation details. Pure react functions receive props and render output. Each time the compo
by dsego 5y ago
This is my understanding, but I just use hooks, don't know the implementation details. Pure react functions receive props and render output. Each time the component is rendered (basically a function call), it reads the props and spits out some DOM nodes (simplified). But you loose the ability to have lifecycle events.
So they invented a mechanism that keeps some hidden state that's tracked for us behind the scenes, and we can then "hook" into that lifecycle state.
The main issue is that it's not a native language construct, but a mini-dsl sort of so you need to have this state machine in mind even thought it's implicit and hidden from you.
Instead of reading the docs, you might want to search online how to write hooks from scratch. It's one of those concepts that needs to click.