Hooks are functions that start with the name use (e.g., useState, useEffect).
They allow functional components to:
-
useState
: Allows functional components to manage state. -
useEffect
: Performs side effects in function components, similar to lifecycle methods in class components. -
useContext
: Provides a way to access the context in functional components. -
useReducer
: Alternative touseState
. It's usually preferred for managing more complex state logic. -
useCallback
: Returns a memoized callback function. -
useMemo
: Returns a memoized value. -
useRef
: Returns a mutable ref object. -
useImperativeHandle
: Customizes the instance value that is exposed when usingref
. -
useLayoutEffect
: Similar touseEffect
, but fires synchronously after all DOM mutations. -
useDebugValue
: Used for displaying custom hook labels in React DevTools.
Rules for Using Hooks:
- hooks can be only used in the react component
- It can be only used in top-level( it must be not called in nested code statements)
Top comments (0)