Knowledge Maxxing
← Back to topic library
Dev MaxxingBeginnerReact75 sec

React hook

A React hook is a special function, like useState or useEffect, that lets a component use features such as state or side effects without being written as a class.

Prerequisite: State

What matters

Hooks let component logic, like managing state, be reused and composed directly inside function components, which is now the standard way most React code is written.

Example

Calling 'const [count, setCount] = useState(0);' inside a component uses the useState hook to add a piece of state to it.

Common misconception

React hooks are not meant to be called conditionally or inside loops; they must be called in the same order every render for React to track them correctly.

Recall question

What capability do hooks give function components that they wouldn't otherwise have?

Keywords and related concepts

React hookuseStatefunction componentstate

Related topics

State
Dev MaxxingBeginner
Effect
Dev MaxxingBeginner