React flashcards: hooks, rendering and React 19
Fifty React cards: state and re-rendering, useEffect and cleanup, memoization, refs, context, Suspense and the React 19 APIs like use, useOptimistic and useActionState.
Practice now
Study without an account
Scheduled with the default Askesis timings. Progress is saved in this browser.
All 50 cards
- 1What is a React component?A function that returns JSX; its name must start with a capital letter
- 2Can a component change its props?No. Props are read-only; change data through state or a callback from the parent
- 3Why
classNameinstead ofclassin JSX?JSX compiles to JavaScript, whereclassis a reserved word (likewisehtmlForforfor) - 4What renders when
countis 0?tsx{count && <Badge count={count} />}A literal0. Use a boolean:{count > 0 && <Badge count={count} />} - 5What should a list item’s
keybe?A stable ID unique among its siblings; array indexes break when items are reordered or removed - 6What happens when a component’s
keychanges?React unmounts it and mounts a fresh one, resetting its state - 7What does
useStatereturn?The current value and a setter; calling the setter schedules a re-rendertsxconst [count, setCount] = useState(0) - 8When should you pass a function to a state setter?When the next state depends on the previous onetsx
setCount((c) => c + 1) - 9What is
countafter one click if it starts at 0?tsxfunction onClick() { setCount(count + 1) setCount(count + 1) }1: both calls read the same snapshot. WithsetCount(c => c + 1)twice it would be2 - 10Why doesn’t the state variable change right after calling its setter?State is a snapshot for the current render; the new value shows up on the next render
- 11What is automatic batching?Since React 18, several state updates in the same event, timeout or promise are combined into one re-render
- 12Add an item to an array in statetsx
setItems([...items, item])Never mutate state (items.push); React compares references. - 13What makes a component re-render?Its state changes, its parent re-renders, or a context it reads changes
- 14What is
useEffectfor?Synchronizing a component with something outside React: subscriptions, timers, the DOM, network connections - 15Clean up an effectReturn a function; React runs it before the effect runs again and on unmounttsx
useEffect(() => { const id = setInterval(tick, 1000) return () => clearInterval(id) }, []) - 16Effect dependency arrays:
[],[a, b], omitted[]runs after mount only;[a, b]runs whenaorbchanges (compared withObject.is); omitted runs after every render - 17What is a stale closure in a hook?An effect or callback that reads an old value because a dependency is missing from its array
- 18Why do effects run twice in development?StrictMode mounts, unmounts and remounts components once to expose missing cleanup; production runs them once
- 19Should you sync derived data with an effect?No. Compute it during render (
const total = items.length); effects for derived state cause extra renders and bugs - 20What does
useMemodo?Caches a computed value between renders until its dependencies change - 21What does
useCallbackdo?Caches a function between renders, so children wrapped inmemodon’t re-render needlesslyuseCallback(fn, deps)equalsuseMemo(() => fn, deps). - 22What does
memodo?Skips re-rendering a component when its props are shallowly equal to last time - 23What does the React Compiler do?Adds memoization automatically at build time, so most manual
useMemo,useCallbackandmemobecome unnecessary - 24What is
useReffor?A mutable.currentthat survives re-renders without causing one; also a handle to a DOM nodetsxconst input = useRef<HTMLInputElement>(null) // <input ref={input} /> input.current?.focus() - 25How do you pass a ref to your own component in React 19?As a regular
refprop;forwardRefis no longer needed for function components - 26Controlled inputtsx
<input value={name} onChange={(e) => setName(e.target.value)} /> - 27Uncontrolled inputThe DOM keeps the value; set it with
defaultValueand read it with a ref orFormData - 28Provide and read context in React 19tsx
const Theme = createContext("light") <Theme value="dark"> <Page /> </Theme> const theme = useContext(Theme) // "dark"Rendering the context itself as a provider replaces<Theme.Provider>. - 29Why can a context make many components re-render?Every consumer re-renders when the provided value changes by reference; memoize object values
- 30When is
useReducera better fit thanuseState?When state has several related fields or many update types; updates go through a pure(state, action) => nextfunctiontsxconst [state, dispatch] = useReducer(reducer, initial) dispatch({ type: 'added', text }) - 31What is a custom hook?A function whose name starts with
useand that calls other hooks, to reuse stateful logic - 32The Rules of HooksCall hooks only at the top level of components or custom hooks, never in loops, conditions or nested functions
- 33What does
use()do in React 19?Reads a promise (suspending until it resolves) or a context; unlike other hooks it can be called conditionally - 34What does
<Suspense>do?Shows itsfallbackwhile something inside it is suspended, such as lazy code or data read withusetsx<Suspense fallback={<Spinner />}> <Comments /> </Suspense> - 35What can’t an error boundary catch?Errors in event handlers, async code like timeouts, server rendering, or the boundary itselfError boundaries are still written as class components.
- 36What does
useTransitiondo?Marks a state update as non-urgent so typing and clicks stay responsive;isPendingtells you it’s in progresstsxconst [isPending, startTransition] = useTransition() startTransition(() => setTab(next)) - 37What does
useDeferredValuedo?Gives you a version of a value that lags behind during heavy renders, like results trailing a search box - 38What is
useOptimisticfor?Showing the expected result of an async action immediately, then settling on the real state when it finishestsxconst [optimistic, addOptimistic] = useOptimistic(messages, (list, msg) => [...list, msg]) - 39What does
useActionStatereturn?[state, formAction, isPending]; the action receives the previous state and the form datatsxconst [error, submit, isPending] = useActionState(saveName, null) // <form action={submit}> - 40What happens with
<form action={fn}>in React 19?Submitting callsfnwith theFormData; it can be async, and React tracks the pending state - 41What does
useFormStatusread?The pending state of the parent<form>, from a component rendered inside it (it comes fromreact-dom) - 42What are React Server Components?Components that run only on the server: they can be async and read data directly, ship no JavaScript, and can’t use state or effects
- 43What does
'use client'mark?A module (and what it imports) as client code: the boundary where Client Components start - 44What does
'use server'mark?Server Functions that client code can call, for example as form actions - 45
useLayoutEffectvsuseEffectuseLayoutEffectruns after DOM changes but before paint, for measuring layout; it blocks painting - 46What is
useIdfor?Generating unique IDs that match between server and client, e.g. to link a label and an input - 47Group children without an extra DOM elementtsx
<> <Title /> <Body /> </>Use<Fragment key={id}>when a fragment needs a key. - 48What does
createPortaldo?Renders children into another DOM node (for modals and tooltips) while keeping React context and events - 49What is “lifting state up”?Moving shared state to the closest common parent and passing it down as props
- 50What causes a hydration mismatch?The first client render differing from the server HTML, e.g. from
Date.now(), random values orwindowchecksMove client-only values into an effect, or render them after mount.
Frequently asked questions
Which React version does this cover?
React 19, while noting where behavior has been the same since React 18.
Do I need TypeScript for these cards?
No. A few snippets use TypeScript generics on refs; the concepts are the same in plain JavaScript.
Does it cover Next.js?
Only the React parts it builds on, like Server Components and the use client and use server directives.
More in Web development
HTML & CSS
Fifty HTML and CSS cards: semantic HTML and accessible forms, specificity and cascade layers, flexbox and grid, stacking contexts and z-index, modern units and container queries.
50 cardsVue
Vue 3 fundamentals: ref vs reactive, computed and watch, props and emits, v-model, directives, slots, single-file components and Pinia stores.
50 cardsAngular
Modern Angular: standalone components, signals, inputs and outputs, dependency injection, RxJS basics, @if and @for, routing and OnPush change detection.
50 cardsNext.js
Next.js App Router basics: server vs client components, layouts, route handlers, server actions, caching, metadata, dynamic routes and middleware.
50 cardsNode.js
Node.js fundamentals: the event loop, ESM vs CommonJS, npm, streams, Buffer, fs/promises, process, error handling, worker threads and a basic HTTP server.
50 cardsGraphQL
GraphQL basics: schema types, queries, mutations, subscriptions, resolvers, variables, fragments, N+1 and DataLoader, introspection and GraphQL vs REST.
50 cards