Introducing a React Hook
The state is mostly local to a component, at least as far as this book is mostly concerned. The natural place for storage would be under a component instance because a component in React defines a piece of UI. So, where is the component instance of a function component in React stored?
It turns out that a component isn't the smallest unit in React. There's a more granular structure called fiber, which is used to represent a piece of element. A fiber performs all the tasks for this element. The element can be as simple as h1
, div
elements, or it can be an artificial element that does things differently. For instance, a "fragment" element can group other elements without displaying itself, or a "memo" element can remember all the elements from the last update.
Actually, a function component is one of the artificial elements that a fiber represents. What a function component does is allow us to define what elements it can display...