hooks

What is hooks ?

  • Profile picture of Mcs
  • by Mcs July 2, 2025

Hooks are special functions introduced in React 16.8 that allow you to "hook into" React state and lifecycle features from functional components. Before hooks, managing state and side effects in React components typically required using class components. Hooks provide a way to achieve the same functionality within simpler functional components.

Most Common Basic Hooks

HookUse
useState()Add state to function components
useEffect()Handle side effects (e.g., API call, DOM updates)
useRef()Create mutable reference (like instance variables)
useContext()Access global/shared data using context

Advanced Hooks in React

HookPurpose
useReducer()Manages complex state logic (like Redux)
useCallback()Memoizes functions to avoid re-creation on re-renders
useMemo()Memoizes values to prevent expensive recalculations
useLayoutEffect()LikeuseEffect but runs synchronously after DOM updates
useImperativeHandle()Customize the refpassed to a child component
useDebugValue()Show custom labels in React DevTools
useDeferredValue()Improve performance during input rendering
useTransition()Mark UI updates as non-urgent to prevent UI blocking

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.