What are the rules of react hook?

In reactjs, hooks are pure JavaScript functions. Writing functions in JavaScript is so easy. Similarly, using hooks inside a component is nothing but calling a function. But we can’t call react hook from every context. React has defined few rules about it.

Following are the rules of using react hook:

Rules of reactjs hook:

Only call hooks at the Top Level. That means we should not call Hooks inside loops, conditions, or nested functions.
Call hooks from react functions. We should not call react hook from JavaScript functions.
Hooks can be called from the context of a custom hook.