React Hooks – Create Custom Hooks

  • What are the rules of creating Hooks?
  • Why use custom hooks?
  • Creating Custom Hook Example 1

What are the rules of creating Hooks?

that’s what allows React to correctly preserve the state of Hooks between multiple useState and useEffect calls. 

https://reactjs.org/docs/hooks-rules.html

Rule: Don’t call Hooks inside loops, conditions, or nested functions

Nested functions
Calling React Hook inside a conditional statement
calling a React Hook inside a loop

Rule: Only Call Hooks from React Functions

Recent Posts