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

Conteúdo do Curso

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:

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 6. Capítulo 4
some-alt