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