Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Rules of Using Hooks | Hooks
Introduction to React
course content

Course Content

Introduction to React

Introduction to React

1. Getting Started: ES6
2. Getting Started: JSX
3. React in Practice
4. React Components
5. Controlling Data & Content
6. Hooks
7. React Router

bookRules of Using Hooks

There are certain rules we must follow while using Hooks to avoid surprises. For the hooks, there are two simple rules:

  1. Only call hooks at the top level;
  2. Only call hooks from React functions.

Top-level means directly inside the React component, and outside of any other code blocks, for example, loops or conditions. The following code shows valid and invalid cases:

Apart from that, calling React hooks in functions other than React components is also invalid:

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 6. Chapter 4
We're sorry to hear that something went wrong. What happened?
some-alt