Wednesday, 2 October 2024

Type of React Hook

 Types of React Hooks:

1.UserState

  • track state in a function component
  • State generally refers to data or properties that need to be tracking in an application
2.UserEffect
  • perform side effects in your components
  • fetching data, directly updating the DOM, and timers
  • useEffect(<function>, <dependency>)
  •         useLayoutEffect is a version of useEffect that fires before the browser repaints the screen.
    • useLayoutEffect can hurt performance(bad performance). Prefer useEffect when possible.
3.UserContext
  • Context is a way to manage state globally
    • useContext(SomeContext)
    • Passing data deeply into the tree
    • Updating data passed via context
    • Specifying a fallback default value
    • Overriding context for a part of the tree
    • Optimizing re-renders when passing objects and functions
4.Usermemo
  • The main difference is that useMemo returns a memoized value and useCallback returns a memoized function
5.UserRef
  • persist values between renders
6.UserReducer
  • The useReducer Hook is similar to the useState Hook.
  • It allows for custom state logic.
7.UserCallback
  • The React useCallback Hook returns a memoized callback function
    • useCallback(fn, dependencies)
    • Skipping re-rendering of components
    • Updating state from a memoized callback
    • Preventing an Effect from firing too often
    • Optimizing a custom Hook
8.useId
  •        useId is a React Hook for generating unique IDs that can be passed to accessibility attributes.
    • Generating unique IDs for accessibility attributes
    • Generating IDs for several related elements
    • Specifying a shared prefix for all generated IDs
    • Using the same ID prefix on the client and the server


No comments:

Post a Comment