0% found this document useful (0 votes)
5 views

react_hooks_summary

Uploaded by

FATHAN ALI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

react_hooks_summary

Uploaded by

FATHAN ALI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

React Hooks Summary

useState:

Used to manage state in functional components. It allows values to change and triggers re-renders

when the state updates.

useEffect:

Runs side effects like fetching data, updating the DOM, or subscribing to services after rendering. It

can be customized to run on specific state changes or only once on mount.

useRef:

Stores mutable values that don't trigger re-renders, like DOM references or previous values. Useful

for accessing and interacting with DOM elements directly.

useContext:

Provides a way to share values (like themes or user info) across components without passing props

manually. It simplifies state management for deeply nested components.

useReducer:

An alternative to useState for complex state logic. It uses a reducer function to handle state

transitions, useful when the state depends on multiple actions.

useCallback:

Memoizes a function to prevent it from being recreated on every render, which can optimize

performance, especially with child components.

useMemo:

Memoizes a value or computation, recalculating it only when specific dependencies change. This

improves performance by avoiding unnecessary recalculations.


useLayoutEffect:

Similar to useEffect, but it runs synchronously after all DOM mutations. It's useful for layout

measurements or directly manipulating the DOM before the paint.

useImperativeHandle:

Customizes the instance value that is exposed to parent components when using ref. It helps control

what functions and properties are accessible from the parent.

You might also like