What are hooks, and what are the rules of hooks?

React hooks and effects · Freshers

Model answer

Hooks are functions such as useState and useEffect that let function components use state and other React features. There are two rules: call hooks only at the top level of a component or custom hook (not inside loops, conditions or nested functions), and call them only from React function components or custom hooks.

React relies on the call order being the same on every render. The eslint-plugin-react-hooks package checks these rules for you.

Learn this topic

React useEffect Explained: Side Effects, Dependencies and Cleanup in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions