2 ms·
I’ve see this argument before but I don’t get it. How is this.setState any simpler? Can you explain how class based components work in any detail? For example,
by thatswrong0 7y ago
I’ve see this argument before but I don’t get it. How is this.setState any simpler? Can you explain how class based components work in any detail? For example, why do we need to call super(props) in the constructor? There’s a whole Dan Abramov post about that one (https://overreacted.io/why-do-we-write-super-props/ https://overreacted.io/why-do-we-write-super-props/)... is that really so straightforward?
Or are you just talking about “pure” functional components? How would you build a full featured application with just those?
I think it’s actually _less_ magical now, because of the required static order of hook invocation. This implies that each component instance has something like an array backing it that keeps track of hooks calls between renders. This array maybe could hold said state value at the index corresponding to the static ordering of that useState call. So then maybe useState just populates the initial value in the array and provides a callback which both sets the value in the array and then queues up a component re-render