Hook (React)
A Hook is a special React function that lets you 'hook into' React features like state and lifecycle from inside a functional component. Hook names always start with 'use', such as useState and useEffect.
React
Before Hooks, only class components could hold state and run lifecycle code. Hooks brought those abilities to simpler function components, and are now the standard way to write React.
Hooks follow two rules: only call them at the top level of a component (never inside loops, conditions, or nested functions), and only call them from React components or other custom Hooks. Following these rules lets React track each Hook correctly between renders.
Examples
JSX — Uses two Hooks together to render a clock that updates the displayed time every second.
import { useState, useEffect } from "react";
function Clock() {
const [time, setTime] = useState(new Date());
useEffect(() => {
const id = setInterval(() => setTime(new Date()), 1000);
return () => clearInterval(id);
}, []);
return <p>{time.toLocaleTimeString()}</p>;
}