Rules of React Hooks
- Hooks should be called only at the top level.
- Don’t call hooks conditonally and inside a loop.
- Hooks should be called only in a functional component but not through regular JavaScript functions.
Introduction to React Hooks
In React, Hooks are functions that allow you to manage state and perform side effects without the involvement of class components. Hooks were introduced in v16.8 of React and they can be accessed only through functional components but not through class components (Hooks were specifically designed for that). Hooks allow you to “hook into” React state and lifecycle features from functional components.