useState, useEffect, useRef, useMemo, useCallback, useContext, useReducer, custom hooks and rules of hooks.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What does useState return?
Show answer
An array with the state value and a setter function
- How do you update state with useState?
Show answer
Call the setter function with the new value
- When does useEffect run if the dependency array is empty?
Show answer
Only once after the initial render (on mount)
- When does useEffect run if you omit the dependency array?
Show answer
After every render
- What is a cleanup function in useEffect?
Show answer
A function returned from useEffect that runs before the effect re-runs or on unmount
- What does useRef return?
Show answer
A mutable object with a .current property
- Does updating a ref cause a re-render?
Show answer
No, updating a ref does not trigger a re-render
- Name a common use case for useRef
Show answer
Storing a reference to a DOM element or accessing it directly
- What is the primary purpose of useMemo?
Show answer
To memoize a computed value and avoid recalculating it on every render
- When should you use useMemo?
Show answer
When you have an expensive computation that does not need to run every render
- What is the primary purpose of useCallback?
Show answer
To memoize a function definition so it maintains the same reference across renders
- Why would you use useCallback?
Show answer
To prevent unnecessary re-renders of child components that depend on the function reference
- What does useContext do?
Show answer
Allows a component to access context values without prop drilling
- What must you do before using useContext?
Show answer
Create a context using React.createContext()
- When should you use useReducer instead of useState?
Show answer
When you have complex state logic or multiple related state updates