Rreact.wiki
← All tools

React Cheatsheet 2026

The hooks, patterns, and APIs React developers reach for every day — kept current and copy-paste ready. Bookmark it and keep it open in a tab.

Core Hooks

useState

Local component state.

const [count, setCount] = useState(0);
setCount(c => c + 1);

useEffect

Run side effects after render.

useEffect(() => {
  const id = setInterval(tick, 1000);
  return () => clearInterval(id);
}, []);

useRef

Mutable value that survives renders.

const inputRef = useRef(null);
<input ref={inputRef} />

useMemo

Memoize an expensive computation.

const sorted = useMemo(
  () => items.sort(cmp),
  [items]
);

useCallback

Stable function identity.

const onClick = useCallback(
  () => doThing(id),
  [id]
);

useContext

Read context without a consumer.

const theme = useContext(ThemeContext);

Patterns

Conditional render

Short-circuit and ternary.

{isLoading && <Spinner />}
{error ? <Err /> : <Data />}

List + keys

Stable keys avoid re-mounts.

{items.map(i => (
  <Row key={i.id} {...i} />
))}

Lifting state up

Share state via the closest parent.

<Parent>
  <Child value={v} onChange={setV} />
</Parent>

Custom hook

Extract reusable logic.

function useToggle(init = false) {
  const [on, set] = useState(init);
  return [on, () => set(o => !o)] as const;
}

Performance

React.memo

Skip re-render if props are equal.

const Row = React.memo(function Row(props) {
  return <li>{props.label}</li>;
});

Lazy + Suspense

Code-split a component.

const Chart = lazy(() => import('./Chart'));
<Suspense fallback={<Spinner/>}>
  <Chart />
</Suspense>

Avoid inline objects

New refs break memoization.

// ❌ style={{margin:8}}
// ✅ const s = {margin:8}; style={s}

TypeScript

Typed props

Describe a component's inputs.

type Props = { label: string; onClick?: () => void };
function Btn({ label, onClick }: Props) {}

Typed state

Give state an explicit type.

const [user, setUser] = useState<User | null>(null);

Event types

Common DOM event types.

(e: React.ChangeEvent<HTMLInputElement>) => {}
(e: React.FormEvent) => {}