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
- 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.
- 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
- The main difference is that useMemo returns a memoized value and useCallback returns a memoized function
- persist values between renders
- The useReducer Hook is similar to the useState Hook.
- It allows for custom state logic.
- 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