What is a Hook?
Now that we have revealed the stripped-down version of the React Hook infrastructure and crafted a function using it, let's give it a spin in a function component:
const Title = () => { const a = _useHook(0) }
The preceding a
variable is assigned a 0
number upon the mount, and then it serves as a state for the rest of the updates.
_useHook
is technically a React hook function. Though it's not an officially supported one, and we crafted it here to demonstrate the infrastructure, it has everything about being a hook function. Let's take a close look at it.
Note
To distinguish the educational hook that we crafted from the officially supported hook, we prefixed the hook name with _
, as in _useHook
.
We’ll further explain the nature of a hook being a function as well as its calling order in the following section.
A hook is a function
A hook is a function that takes input arguments and returns a value, and it carries...