Irbisa · Cheatsheet
Performance
React.memo, useMemo and useCallback, React Compiler, code splitting and lazy, list virtualization, the Profiler, Core Web Vitals, bundle size
What are the main ways to make a React app faster, and in what order would you apply them?
What does
React.memodo, and when does a memoized component still re-render?interface RowProps { label: string; onSelect: (label: string) => void;} const Row = memo(function Row({ label, onSelect }: RowProps) {…Find the bug:
Chartis wrapped inmemo, yet the Profiler shows it re-rendering on every keystroke in the search box.const Chart = memo(function Chart({ options, onPointClick }: ChartProps) { return <canvas data-type={options.type} onClick={() => onPointClick(0)} />;}); function Dashboard({ data }: { data: number[] }) { const [query, setQuery] = useState(''); return ( <> <input value={query} onChange={(e) => setQuery(e.target.value)} /> <Chart options={{ type: 'line', data }} onPointClick={(i) => console.log(data[i])} /> </> );}What does memoization cost, and when do
React.memo,useMemooruseCallbackmake things worse?How can you stop needless re-renders without memoization, by moving state down or passing components as
children?// before: every scroll event re-renders ExpensiveTreefunction SlowPage() { const [scrollY, setScrollY] = useState(0); return ( <div onScroll={(e) => setScrollY(e.currentTarget.scrollTop)}> <Header shadow={scrollY > 0} />…What is the React Compiler, and does it make
useMemo,useCallbackandReact.memounnecessary?How do you find out which components re-render and why, using the React DevTools Profiler?
function onRender( id: string, phase: 'mount' | 'update' | 'nested-update', actualDuration: number, baseDuration: number,) {…What is code splitting, and how do
React.lazyandSuspenseload a component on demand?const SettingsPage = lazy(() => import('./SettingsPage'));const preloadSettings = () => import('./SettingsPage'); export function App() { const [open, setOpen] = useState(false); return (…Find the bug: the lazy editor flashes its fallback and loses everything typed each time the parent re-renders.
function NotePage({ noteId }: { noteId: string }) { const [saved, setSaved] = useState(false); const Editor = lazy(() => import('./Editor')); return ( <Suspense fallback={<p>Loading editor...</p>}> <Editor noteId={noteId} onSave={() => setSaved(true)} /> {saved && <p>Saved</p>} </Suspense> );}Find the bug: the chart is loaded with
lazy, yet the whole chart library is still in the main bundle.// Dashboard.tsximport { lazy, Suspense, useState } from 'react';import { CHART_COLORS } from './RevenueChart'; const RevenueChart = lazy(() => import('./RevenueChart')); export function Dashboard() { const [show, setShow] = useState(false); return ( <div style={{ borderColor: CHART_COLORS.primary }}> <button onClick={() => setShow(true)}>Show revenue</button> {show && ( <Suspense fallback={<p>Loading chart...</p>}> <RevenueChart /> </Suspense> )} </div> );}What is list virtualization (windowing), when do you need it, and how does it work?
function LogList({ lines }: { lines: string[] }) { const parentRef = useRef<HTMLDivElement>(null); const virtualizer = useVirtualizer({ count: lines.length, getScrollElement: () => parentRef.current, estimateSize: () => 24,…What are the Core Web Vitals (LCP, INP, CLS), and what in a React app usually hurts each one?
What do
<link rel="preload">,prefetchandpreconnectdo, and how do React 19'spreloadandpreinitAPIs use them?import { preconnect, prefetchDNS, preinit, preload } from 'react-dom';import { Link } from 'react-router'; export function CheckoutPage() { // called during render: with SSR they go out in the HTML before the form needs them preconnect('https://api.payments.example');…How do you load web fonts without invisible text or layout shift?
/* in <head>, for the one file used above the fold: <link rel="preload" href="/fonts/inter-latin.woff2" as="font" type="font/woff2" crossorigin> */ @font-face { font-family: 'Inter'; src: url('/fonts/inter-latin.woff2') format('woff2');…When would you move work to a Web Worker in a React app, and how do you talk to it?
// sort.worker.ts: runs on its own thread, no DOM and no Reactself.onmessage = (e: MessageEvent<Row[]>) => { const sorted = [...e.data].sort(compareRows); // the 300 ms part self.postMessage(sorted);};…Why does a click or keystroke feel slow (poor INP) in a React app, and how do you break up long rendering work?
function ReportPage({ rows }: { rows: Row[] }) { const [tab, setTab] = useState<'summary' | 'details'>('summary'); const [isPending, startTransition] = useTransition(); function selectTab(next: 'summary' | 'details') { // the heavy tab renders in interruptible slices…What does the
<Activity>component added in React 19.2 do, and how can it make navigation feel faster?function Tabs({ tab }: { tab: 'feed' | 'profile' }) { return ( <> <Activity mode={tab === 'feed' ? 'visible' : 'hidden'}> <Feed /> </Activity>…How do you measure a React app's performance in production rather than on your own machine?
import { onCLS, onINP, onLCP, type Metric } from 'web-vitals'; function send(metric: Metric) { const body = JSON.stringify({ name: metric.name, value: metric.value,…How do you find out what makes a React bundle large, and how do you shrink it?
A table with 5,000 rows freezes on every keystroke in its filter box. Walk through how you would diagnose and fix it.