What Is a Hook?
Learn about custom React hook functions and their implementation in function components.
We'll cover the following...
Custom React hook function
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 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 officially supported, and we crafted it here to demonstrate the infrastructure, it has everything required to be a hook function. Let's take a close look at it.
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 ...