Explore tens of thousands of sets crafted by our community.
ReactJS Hooks
20
Flashcards
0/20
useLayoutEffect
Runs synchronously after all DOM mutations. Example: useLayoutEffect(() => { measureLayout(); }, [dependencies]);
useCallback
Memorizes a callback function. Example: const memoizedCallback = useCallback(() => { doSomething(a, b); }, [a, b]);
useMemo
Memorizes the calculated value. Example: const memoizedValue = useMemo(() => computeExpensiveValue(a, b), [a, b]);
useMutableSource
Used to access the state from an external, mutable source in a concurrent-safe way. Please note that this hook has been replaced by useSyncExternalStore in React 18.
useDebugValue
Used to display a label for custom hooks in React DevTools. Example: useDebugValue(value);
useOpaqueIdentifier
Returns an object that is stable across server and client rendering, useful for generating unique IDs (deprecated, use useId instead).
useSyncExternalStore
Subscribes to an external mutable source. Example: const state = useSyncExternalStore(store.subscribe, store.getState);
useCacheRefresh
Triggers a refresh of cached data if updates are detected (experimental and not a part of the stable API).
useRef
Returns a mutable ref object. Example: const myRef = useRef(initialValue);
useEffect
Used to perform side effects in functional components. Example: useEffect(() => { document.title = `You clicked {count} times`;}, [count]);
useImperativeHandle
Customizes the instance value that is exposed when using ref. Example: useImperativeHandle(ref, () => ({ focus: () => { inputRef.current.focus(); } }), [inputRef]);
useDeferredValue
Defers the value until after the next render. Example: const deferredValue = useDeferredValue(value);
useEvent
Enables stable event callbacks, preventing capture of values, props, and state (experimental in React 18). Example: const stableOnClick = useEvent(() => { console.log('clicked'); });
useInsertionEffect
Used to inject styles into the DOM before layout occurs. Example: useInsertionEffect(() => { const sheet = new CSSStyleSheet(); sheet.replaceSync('* { transition: none; }'); });
useState
Allows you to add state to functional components. Example: const [count, setCount] = useState(0);
useContext
Gives you access to the data in React Context. Example: const value = useContext(MyContext);
useId
Generates a unique and stable identifier. Example: const id = useId();
useTransition
Helps optimize the rendering of non-urgent updates. Example: const [isPending, startTransition] = useTransition();
useSelector
Used with React-Redux to efficiently select data from Redux store. Example: const data = useSelector(state => state.data);
useReducer
An alternative to useState which accepts a reducer function. Example: const [state, dispatch] = useReducer(reducer, initialState);
© Hypatia.Tech. 2024 All rights reserved.