React Hooks are a feature introduced in React version 16.8 that allow you to use state and other React features without writing a class. They are JavaScript functions that let you "hook into" React state and lifecycle features from function components Source 3.
There are two main rules for using hooks in React:
-
Only call hooks at the top level: Don't call hooks inside loops, conditions, or nested functions. Instead, always use hooks at the top level of your React function, before any return keyword Source 2.
-
Only call hooks from React function components or custom hooks: You should never call hooks from regular JavaScript functions. However, you can call hooks from React functional components and custom hooks Source 2.
These rules are enforced by the ESLint plugin called `eslint-plugin-react-ho