Short answer
Hooks let you use React features from a function component, without writing a class. The hooks reference says a hook starts with use. useState keeps a value and a setter that triggers a re-render. useEffect synchronizes the component with an external system. Call them only at the top level of a React function.
Last verified against the sources listed below.
Key takeaways
- The hooks page says hooks let you use React features from your components.
- Rules of Hooks: call them at the top level of a function component or a custom hook.
- useState returns the current state and a set function that updates the next render.
- useEffect runs setup and optional cleanup to sync with something outside React.
- The React 16.8 release post says hooks became available in that stable release.
What are react hooks is a question about functions, not about a new language. The hooks reference says hooks let you use React features from your components. You can use the built-in hooks or combine them into your own.
A function whose name starts with use is a hook, according to the Rules of Hooks. The 16.8 release post says that with React 16.8, hooks are available in a stable release, and that they let you use state and other React features without writing a class.
JavaScript is still the language of the component. Hooks are a React rule about where those functions may run.
What does the hooks page say?
Hooks are the functions that expose React features inside a component. The reference groups the built-in ones by job.
State hooks remember information. useState declares a state variable you can update directly. useReducer declares state whose update logic lives in a reducer. useOptimistic shows a different state while an async action is pending.
Context hooks read a value from a distant parent. Ref hooks hold information that is not used for rendering, such as a DOM node, and updating a ref does not re-render. Effect hooks connect a component to an external system.
Performance hooks such as useMemo and useCallback cache work. Other hooks, including useId and useDebugValue, are described as mostly for library authors.
You can also define your own hook as a JavaScript function. The rules page says a custom hook may call other hooks, because it is supposed to be called while a function component is rendering.
Where may you call a hook?
Call a hook at the top level of a React function. The rules page says you can call hooks while React is rendering a function component, or at the top level of a custom hook.
Do not call them inside conditions, loops, nested functions, or try / catch / finally. Do not call them after a conditional return, in an event handler, inside a class component, or inside the function you pass to useMemo, useReducer, or useEffect. The page says breaking the rules can surface an error, and it points at eslint-plugin-react-hooks to catch mistakes.
The 16.8 post says the same lint package was the recommended way to enforce hook practices, and it shows a rule named react-hooks/rules-of-hooks. That post also says hooks have no breaking changes and that classes were not being removed. New hook code can sit beside existing class code.
What does useState return?
useState returns the current state and a function that updates it. The useState reference shows const [state, setState] = useState(initialState).
The return value is an array of exactly two items. On the first render, the state matches initialState. After that, the initial argument is ignored. If you pass a function as the initial state, React treats it as an initializer, calls it when initializing, and stores the return value.
The set function schedules the next state and a re-render. It does not change the variable you already read in this run. You can pass the next value, or an updater function that receives the pending state.
The set function has no return value. React compares the next value with Object.is and can skip a re-render when the value is the same.
The bracket syntax is array destructuring. MDN says that syntax unpacks array values into distinct variables. javascript.info says the array itself is not modified. The React convention is the pair [something, setSomething].
What does useEffect connect?
useEffect connects the component to an external system. The useEffect reference defines an external system as code React does not control, such as a network connection, a browser subscription, or a third-party widget.
You pass a setup function and an optional list of dependencies. Setup may return a cleanup function. React runs setup when the component commits.
When dependencies change, it runs cleanup with the old values, then setup with the new ones. Cleanup runs a final time when the component leaves the page. If you omit the list, the effect re-runs after every commit.
The page says effects only run on the client, not during server rendering. It also says not to use an effect to orchestrate data flow inside the app. If you are not synchronizing with an external system, you probably do not need one. In development, Strict Mode runs an extra setup and cleanup cycle before the first real setup.
How do the two hooks differ?
useState stores component memory. useEffect reaches outside React. The table uses only the reference pages.
| Question | useState | useEffect |
|---|---|---|
| Role on the hooks page | Declares a state variable you update directly | Connects a component to an external system |
| Call shape | useState(initialState) |
useEffect(setup, dependencies?) |
| Return value | An array: current state, then the set function | undefined |
| When the work applies | The set function updates the next render | Setup runs after commit; cleanup can reverse it |
| A limit both pages share | Top level of a component or your own hooks only | Top level of a component or your own hooks only |
A counter that stores a number is a useState job. A chat room that connects and disconnects as roomId changes is the useEffect example. The effect sample also uses useState for the server URL, so the two hooks often appear in the same function. They still do different work.
Do hooks replace classes?
Hooks are the way to use state and effects without a class. They do not delete class components.
The 16.8 post says you do not have to rewrite an existing app overnight, and that hook components work beside class components. It also says that, at that release, getSnapshotBeforeUpdate and componentDidCatch had no hook equivalent. The current rules page is stricter about call sites: a hook inside a class render method is marked as unsupported. The fix the page shows is to write a function component.
JavaScript vs React is the wider split between the language and the UI library. Hooks sit on the React side of that split.
An SVG to JSX converter produces a React component, which is the kind of function where a top-level useState call is allowed. It does not turn a class into a hook. ---
Frequently asked questions
Can you call a hook inside a condition?
No. The Rules of Hooks page says not to call hooks inside conditions, loops, nested functions, or try, catch, and finally. Call them at the top level of a function component or a custom hook, before any early return. The useState and useEffect pages repeat that limit. If the state belongs in a branch, extract a new component and put the hook there.
Does calling the setter change state immediately?
No. The useState page says the set function updates state for the next render. If you read the variable after calling the setter in the same event, you still get the old value. React applies updates after the event handlers run. If the next value is the same under Object.is, React can skip re-rendering that component and its children. An updater function receives the pending state.
When does useEffect run?
The useEffect page says React runs setup when the component commits. If you return a cleanup function, React runs that cleanup before the next setup when dependencies change, and again when the component is removed. Omit the dependency list and the effect re-runs after every commit. Effects run on the client only. They do not run during server rendering.
Did hooks remove class components?
No. The React 16.8 post says hooks let you use state and other features without writing a class, and that classes were not being removed. Hook components can sit beside class components. The current rules page still forbids calling a hook inside a class. Write a function component instead. That post also said two uncommon class methods had no hook equivalent then.
Why is the state pair written in brackets?
useState returns an array of two values, the current state and the set function. The docs unpack that array with destructuring, written as a pair of names in brackets. MDN says destructuring unpacks array values into distinct variables. The javascript.info guide says this copies items out and does not modify the source array. The bracket form is the convention the React page shows.
Sources
- Built-in React Hooks · React, 2026
- useState · React, 2026
- useEffect · React, 2026
- Rules of Hooks · React, 2026
- React v16.8: The One With Hooks · React, 2026
- Destructuring · MDN, 2026
- Destructuring assignment · javascript.info, 2026