Ask HN: What do you think about React Hooks?
1–7 of 7 posts
Re: Ask HN: What do you think about React Hooks?
#2Immediately after seeing the first example, I'm left wondering what happens if I called useState(0) twice? Does it produce references to the same state object or two separate ones? Does it throw an error? I see "count" and "setCount" being destructured, but where are they defined? Through static analysis during a special build step, through getters, or what?
Re: Ask HN: What do you think about React Hooks?
#3At first glance, hooks are hard to reason about. They encourage changing pure functions into stateful functions that return different results depending on when they were called. Immediately after seeing the first example, I'm left wondering what happens if I called useState(0) twice? Does it produce references to the same state object or two separate ones? Does it throw an error? I see "count" and "setCount" being de…
Re: Ask HN: What do you think about React Hooks?
#4At first glance, hooks are hard to reason about. They encourage changing pure functions into stateful functions that return different results depending on when they were called. Immediately after seeing the first example, I'm left wondering what happens if I called useState(0) twice? Does it produce references to the same state object or two separate ones? Does it throw an error? I see "count" and "setCount" being de…
The first time the component renders, each individual call to `useState` results in a new unique-to-that-component state value being stored behind the scenes. React builds a linked list of all hooks attached to that function component the first time you run it, and then reads from that linked list in future re-renders. So, when you run it again, and `useState()` call #1 occurs, it reads the value and the setter funct…
What's saved in lines of code is lost in expressiveness.
Feels like a step toward Ruby-like magic.
Re: Ask HN: What do you think about React Hooks?
#5Earlier quoted context omitted.
The first time the component renders, each individual call to `useState` results in a new unique-to-that-component state value being stored behind the scenes. React builds a linked list of all hooks attached to that function component the first time you run it, and then reads from that linked list in future re-renders. So, when you run it again, and `useState()` call #1 occurs, it reads the value and the setter funct…
This is so much more complicated than the class approach. What's saved in lines of code is lost in expressiveness. Feels like a step toward Ruby-like magic.
Re: Ask HN: What do you think about React Hooks?
#6Earlier quoted context omitted.
The first time the component renders, each individual call to `useState` results in a new unique-to-that-component state value being stored behind the scenes. React builds a linked list of all hooks attached to that function component the first time you run it, and then reads from that linked list in future re-renders. So, when you run it again, and `useState()` call #1 occurs, it reads the value and the setter funct…
This is so much more complicated than the class approach. What's saved in lines of code is lost in expressiveness. Feels like a step toward Ruby-like magic.
While I understand the argument that hooks encourage to make dumb components stateful this is already the case with class based components. At the end of the day a developer is responsible for separating concerns of his application and he can fail to do so with class based components and hooks the same way.
Re: Ask HN: What do you think about React Hooks?
#7Use Custom Hooks with React Class Components. Compatible React >= 16.0.0