3 ms·
> Stateful "functions" is just so asinine I don't even know where to begin I feel like the React team did a bad job at communicating that the functions are sti
by unchar1 6y ago
> Stateful "functions" is just so asinine I don't even know where to begin
I feel like the React team did a bad job at communicating that the functions are still stateless. The functions themselves never hold state, they just access the state that react holds for each component through hooks.
I think this confusion is further fueled by the fact that most people feel
render () {
return <Button />
}
calls the `Button` function inside `render`, but what it actually does is that it registers the `Button` function in React, telling it "here's how you can create what I want", it doesn't actually call the function. The actual call is done by React, if and when it wants to.
Hooks extends that idea by letting you say "Here's how I want to update my component".
The component functions you write in React are a "description" telling React how to create that component. With hooks you can now "describe" how to update that component with new changes. I feel like hooks force you to let go of the control you thought you had with class-based components. Whether that's a good thing is up upto you.