EasyNot started
React cheatsheet
Quick reference for JSX, hooks, and common interview topics — pairs with the interactive demos below.
React cheatsheet
Quick reference for JSX, hooks, and common interview topics. Pairs with the interactive demos below.
Components & JSX
- Props are read-only; destructure in the signature:
function Card({ title }: Props). - Conditional UI:
{cond && <A />},{cond ? <A /> : <B />}. - Lists: stable
key(id, not index when items reorder or insert). - Children:
React.ReactNode— slot content between tags.
Hooks (when to use)
useState— local UI state.useReducer— related state with explicit transitions.useEffect— sync with external systems (fetch, subscriptions, non-React APIs). Include all reactive values you read in deps; cleanup to unsubscribe / cancel.useLayoutEffect— DOM measure/layout before paint (rare).useMemo— expensive pure computations.useCallback— stable function refs for memoized children or effect deps.useRef— mutable value, DOM nodes, timers, latest value without re-render.
Forms & data
- Controlled:
value+onChange(React owns state). - Uncontrolled:
defaultValue+refto read. - Prefer React Query / SWR (or framework loaders) over raw
useEffect+fetchfor caching and deduping.
Performance & context
React.memo— skip re-render when props are shallow-equal (child must be pure).- Split state so frequent updates don't re-render heavy subtrees.
- Avoid new object/array/function props every render when passed to
memochildren. - Context — good for rarely changing globals (theme, auth); avoid as a general state bus.
TypeScript snippets
type Props = { title: string; onSave?: () => void }- Events:
React.ChangeEvent<HTMLInputElement>,React.MouseEvent<HTMLButtonElement>.
Common pitfalls
- Missing or wrong effect dependencies → stale data or infinite loops.
- Storing derived state in
useState+ syncing withuseEffect— derive during render instead. - Mutating state/props in place — always new references for objects/arrays when updating.