Don’t call Hooks from regular JavaScript functions. Instead, you can:
- Call Hooks from React function components.
- Call Hooks from custom Hooks (we’ll learn about them on the next page).
- Call Hooks from custom Hooks (we’ll learn about them on the next page).
Check your fucntion in the code, fucntion should be a React JS function not general JavaScript function. A React function should have following four things into it.
React functions:
- Follow React component naming convention, i.e. they must be Capitalized
- Take a single props object argument
- Return valid JSX
- React functions are NEVER invoked. A reference to them is passed or they are referenced as JSX