React: Hooks, State, Context and JSX Reference Guide
By DevShelfHub
Components, JSX, hooks, context, suspense, refs, forms — the day-to-day React API as you actually use it.
87 items
◷ 7 min
Hooks
State
JSX
Start hereQuick start · 6 you’ll reach for daily
Componentfunction Foo() {…}
Stateconst [x, setX] = useState(0)
EffectuseEffect(() => …, [dep])
MemouseMemo(() => …, [dep])
RefuseRef<HTMLInputElement>(null)
ContextuseContext(MyContext)
Target versions · paceVersions
Targets:react ≥ 19react-dom ≥ 19typescript ≥ 5.5
Sheet pins to React 19+. use(), the new
<form action> + useActionState,
server / async components, and the compiler are stable surface. Class components and legacy lifecycle
methods (componentDidMount, …) still work but the rows below
show function-component patterns.
scaffold · deps · toolingSetup
bash
# New app — Vite is the default starter
npm create vite@latest my-app -- --template react-ts
cd my-app && npm install && npm run dev
# Or use a meta-framework
npm create next-app@latest my-app # Next.js
npm create remix@latest my-app # Remix / React Router
# Add packages you'll reach for daily
npm install @tanstack/react-query # server state
npm install zustand # local global state
npm install react-hook-form zod # forms + validation
npm install -D vitest @testing-library/react @testing-library/user-event
# Type-check + lint (TS projects)
npx tsc --noEmit
npx eslint . --fix
Don’t put everything in one. Frequent + rare updates → separate providers.
Memoise the value object
useMemo(() => ({ a, b }), [a, b]). Otherwise every render reseats everyone.
Custom hook wrappers
useTheme() hides context + asserts non-null.
Context is not a state manager. For deeply-shared mutable state with selectors, reach for Zustand,
Jotai, or Redux Toolkit. Context updates everyone subscribed; selectors don’t.
async UISuspense & data fetching
<Suspense fallback={…}>
Boundary that catches suspending children.
<ErrorBoundary fallback={…}>
Pair with Suspense for errors.
const data = use(promise)
19 Suspend on a promise. Pass a cached one!
useSuspenseQuery({ queryKey, queryFn })
react-query Suspense-compatible variant.
streaming SSR / Server Components
Suspense streams chunks as they resolve.
startTransition(() => setX(…))
Mark a state update as non-urgent — doesn’t block input.
Co-locate state with the smallest consumer.
Lift state up only when two siblings need it. State at the top of a tree means every keystroke re-renders
the whole subtree.
Reach for react-query (or SWR) for server state.useEffect + useState for fetching is a
well-trodden tar pit (race conditions, no cache, no retry). The libraries solve it once.
Type your hooks with TypeScript.useRef<HTMLInputElement>(null),
useState<User | null>(null) — catches null-deref + wrong-DOM-element bugs
at compile time.
Common trapsWatch out for
Closures capture stale values inside effects.
Missing a dependency in useEffect means the effect reads an old
setX / state. Use the functional updater or list the dep.
Array index as key reuses the wrong instance.
Reordering or filtering keeps the old component mounted at that index with the new data. Use a stable
ID.
Avoid setState in render.
It triggers an infinite render loop. Move it into an effect, an event handler, or compute the value
derived from state instead of storing it.
React is a JavaScript library for building user interfaces through reusable components. It is used to build single-page apps, dashboards, e-commerce frontends, and mobile apps via React Native. React 19 added server components, the compiler, and use() for Suspense-based data fetching.
What are React hooks?
Hooks are functions that let function components use state, side effects, context, refs, and performance optimizations. The built-in hooks are useState, useEffect, useContext, useRef, useMemo, useCallback, useReducer, and useId. Custom hooks are regular functions that start with use.
What is the difference between useState and useReducer?
useState is for simple, independent state values — a number, string, or boolean. useReducer is better when the next state depends on the previous one, when state has multiple sub-values that move together, or when the update logic is complex enough to warrant a named reducer function.
What is React Context used for?
Context provides a way to pass data through the component tree without prop drilling. Create a context with createContext, wrap the subtree in a Provider, and read the value anywhere inside with useContext. Use it for themes, authenticated user data, locale settings, and similar global state.
Is React free to use?
Yes. React is open source and maintained by Meta under the MIT license. It is free for personal and commercial use with no restrictions.