What are Hooks in ReactJs?
Hooks are special functions, which lets you add local state, perform side effects and add other React features to the functional component. You cannot use Hooks in the "class component", they are only for the "functional component".
Side Effects are the operations like mutating DOM, setting timer, fetching data from the 3rd party API etc.
Hooks that are usually used in every React applications are:
- useState
- useEffect
- useContext
Some additional Hooks are:
- useReducer
- useCallback
- useMemo
- useRef
- useImperativeHandle
- useLayoutEffect
- useDebugValue
Rules of Hooks:
- Only call Hooks at the top level.
- Only call Hooks from the react functions.
To know more about Hooks, visit this page.