React
React components, state, hooks and talking to an API.
Start here
Fundamentals
- One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
- A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
- How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
- Semantic HTML: header, nav, main, aside and footer as Page Landmarks
The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.
- HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
Follow a sign-up form's answers out of the page: label and id, name as the key, browser validation, the query string a GET form builds, and why POST hides it. Plus the most common bug, an input with no name.
- CSS Basics: Selectors, Which Rule Wins, and the Box Model
HTML says what each piece is, CSS says how it looks. Learn the parts of a rule, five selectors, why an id rule beats a class rule, and how padding, border and margin add up to 348px unless you use border-box.
- CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
Flexbox lines things up in one direction, Grid lays out rows and columns at once. Build a nav bar, a wrapping card row and a five-part dashboard with named grid areas, and see what breaks without flex-wrap.
- Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
One page that fits a phone and a wide screen, and a dark mode with one small button. The viewport line, mobile-first min-width queries, clamp() for fluid headings, container queries, and colour tokens switched by data-theme.
- JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
The JavaScript you use every day, for people who already know another language: running files with Node, const and let, arrows, destructuring, spread, modules, and the five things that surprise almost everyone. Every output is from a real run.
- JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
Four orders through map, filter, reduce, find, some, every, sort and Object.entries, traced one element at a time. Why [10, 9, 1].sort() gives [1, 10, 9], and what reduce does without a start value.
- Async JavaScript: Promises, async/await, fetch and Promise.all
A promise is a box that fills later. Follow one through pending and fulfilled, see what await really pauses, why a 404 does not reject fetch, why res.json() is a second promise, and how Promise.all cut 591 ms to 309 ms.
- JavaScript in the Page: the DOM, querySelector and Events
Find, listen, change: one sign-up page traced through the DOM tree, querySelector, input and submit events, preventDefault, textContent, classList and append. Then the bug that explains why React exists.
- npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
Three names in package.json became 17 packages in node_modules. Follow npm install to the registry and back, read the lock file, then watch Vite serve one file per request in dev and build three hashed files for production.
- TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
addTip(40, "5") returns 405 in JavaScript with no error. TypeScript stops it before it runs. Annotations, inference, interfaces, optional properties, unions with narrowing, generics vs any, and type vs interface, with real tsc messages.
- Why React, JSX and Components: The Page as a Function of Data
The same task card built twice: by hand with the DOM, and as a React component. See what JSX compiles to, why a component is just a function, the four JSX rules with their real compiler errors, and how createRoot puts the tree on the page.
- React Props and Composition: Data Down, Calls Up, Children in the Slot
Follow props from a parent's tag into a component and onto the page: one props object, destructuring, an interface with an optional prop and a default, the read-only rule, a callback that goes back up, and the children slot that lets one Card hold anything.
- Routing With React Router: One Page, Many Addresses
A task app with five routes: how the router picks the best match, why Link makes zero requests while a plain a tag downloads the app again, the Outlet slot, the useParams string trap (TS2367), useNavigate after a save, a not-found page and the 404 on refresh.
- React Component Tests With Vitest and Testing Library: Test What the User Sees
Four component tests for a React task board: the four-line Vitest config, a render-find-act-check test, the real failure when a test asks for 'Add' but the page says 'add', and a vi.fn spy for one component on its own.
- End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
Two Playwright journeys for a React task board in real Chromium: the webServer block that starts the app, auto-waiting in the call log, a first draft that times out on '6 of 6 shown', and the page snapshot and trace that show the test was wrong, not the app.
- Why AI-Built Websites All Look the Same, and Four Levels That Fix It
The indigo gradient, the buzzword headline, three equal emoji cards, Inter everywhere. See why AI tools fall into the same page, and fix it with tokens, your own assets, a font pairing and real copy.
- Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
A newspaper tells you where to look first. Learn the four tools of visual hierarchy, the 8-point spacing scale and proximity, then fix a cluttered workshop card by changing only its CSS.
- Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
Give every colour a job and a number: the 60-30-10 split, semantic tokens like --danger, a small contrast.js that computes WCAG ratios, and a dark palette that keeps its meaning where filter: invert(1) does not.
- Typography That Sells: Type Scale, Line Length and Free Font Pairings
Free fonts that do not look free: a type scale with base 1rem and ratio 1.25, lines of 65ch, three Google Fonts pairings for editorial, product and friendly pages, and a font selector in DESIGN.md.
- The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
A tour of the building blocks almost every app is made of: buttons, badges, inputs, selects, cards, tables, tabs, navigation, dialogs, drawers, toasts and empty states, with their states and their shadcn/ui names.
- Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
A design token is a name for a value, like colour 47 on a paint chart. Build primitive and semantic tokens in tokens.css, reuse the same names in a Tailwind CSS 4 @theme block, and re-skin a card by changing one line.
- Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
Style a React task card with Tailwind CSS 4: install the Vite plugin, read utility classes, go from one column to two with md:, and add hover, focus and dark mode with one prefix each.
- shadcn/ui in React: Components You Own, Edit and Commit
shadcn/ui copies a button, a card and a dialog into your src folder as plain files. Set it up with init and add, read the cva variants in button.tsx, turn every default button indigo with one edit, and use Card and Dialog in a small page.
- Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
Name a colour once and one switch changes the whole page: tokens.css with :root and .dark values, @theme inline in index.css, a React page with only token classes, a ThemeToggle that flips one class on html, and what one hard-coded bg-white breaks.
- Motion in React: Entrance, Hover, Exit and Layout Animations
Small animations that make an app feel premium, with the motion package: a staggered entrance, a springy button, a list row that slides out while the others glide up, a reduced-motion setting, and the missing AnimatePresence bug.
- A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
Build a small sales dashboard in React: four stat cards, a Recharts line chart that disappears when its parent has no height, and an orders table that sorts with one boolean in state, all in a Tailwind grid.
- Accessibility in Practice: Dialogs, Menus and the Keyboard in React
What shadcn/ui and Radix give you for free and what you still check yourself: a dialog that traps focus and gives it back, a menu driven by arrow keys, the ARIA attributes in the real DOM, and a div-button that Tab skips.
- Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
Turn 'make it nice' into a target: pick a reference page, copy its exact colours, type, spacing, radius and motion into DESIGN.md, and have the agent build a new Today page from only those values.
- Components, Variants and Variables: One Design System in Figma and in CSS
Build a button, badge and card once, give them variants, and bind every colour to a variable with Light and Dark modes. Then see the same set in HTML: tokens.css, modifier classes and data-theme.
- Figma MCP Server: Build a React Component From a Frame, Then Write It Back
The Figma MCP server lets a coding agent read real frames, variables and Code Connect mappings instead of guessing from a screenshot. Build a TaskCard component from named tokens, render it with Vite, then write it back into Figma as a new frame.
- Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
Go from a written brief and a reference picture to a page you can click in Claude Design, check it like a user, then hand a complete bundle to Claude Code and ask for a plan before it changes any files. Shown on a Study Planner dashboard.
- Critiquing AI-Generated UI: Six Checks for Every Screen
An AI tool can build a tidy-looking dashboard in seconds and still hide six problems. Review it with six questions, measure the contrast with a ten-line script, and fix each issue with a small CSS change, before and after.
- The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
New AI design tools arrive every month, but they fall into three kinds: prompt to UI (Stitch, Figma Make), prompt to app (v0, Lovable, Bolt) and design to code (Figma MCP, Stitch MCP). Learn what each one gives you and which to reach for.
- Your Brand Rules Folder: One Folder Every AI-Built Page Follows
Every time you ask an agent for a new page it makes its own choices, and your pages drift apart. Keep a brand folder (logo, colours, font, a short rules file) in the project, point the agent at it, and every page comes out matching.
- The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
A vague request gets you the average AI page: purple gradient, a headline that could sell anything, three identical emoji cards. One short prompt in plain sentences, with no technical values, gives the agent decisions to follow. Shown on a weekend workshops page.
- UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
Paste one plain prompt for a red blog into Figma Make, Google Stitch and ChatGPT and you get three different designs in a few minutes: an editable Figma design, a full design system plus a page, and a picture that ChatGPT turns into one HTML file.
- Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
One sentence can describe many layouts; a picture describes one. Upload a napkin sketch or an old screenshot to Google Stitch, say what to keep and what to change, and get an editable screen. Shown on Orbit's settings page.
- Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
A Stitch export is full of hard-coded values like bg-[#F8FAFC] and rounded-[10px]. Map them to your own tokens (bg-surface, rounded-card, bg-brand) through Figma variables, a Tailwind @theme inline block, or the Stitch MCP server, then fix states, accessibility and data by hand.
- Figma Make: Prompt to Prototype With a Four-Part Prompt
Figma Make turns a prompt into a clickable draft in minutes. Write the prompt in four parts (role, content, style, constraints), check the draft for hierarchy, states and tokens, refine with one-change follow-ups, and move to real code when you start fixing details by hand.
- Upgrade a Dated UI From One Screenshot (or a Reference Image)
A booking page that works but looks years old gets a modern look from one screenshot and one plain request to the agent. Then an old blog takes on the feel of a reference image while keeping every post and link. The picture shows what to change; your words say what must stay.
- States and Feedback: Make Every Click Get an Answer
A newsletter form that ignores your clicks, shows a vague Error in the corner and leaves a blank list is not broken in code; it just never answers. Describe the missing moments to the agent and get hover, pressed, sending, success, a field error and a friendly empty list.
- A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
One short SKILL.md makes Claude Code take a screenshot of your page, score it on hierarchy, spacing, contrast, consistency and copy against DESIGN.md and a reference, apply the three biggest fixes, and repeat for at most three rounds before handing the decision back to you.
- Copy Without the AI Tells: A Copy Pass on a Landing Page
Default AI copy says unlock, seamless and elevate your workflow, and leaves you unable to tell what the product does. Learn the five tells, rewrite Orbit's landing page line by line with real names and features, and hand the AI your facts so it does the pass for you.
Hooks
- React State, Events, Lists and Conditional Rendering: Follow One Click
Follow one click through a React counter, render by render: what useState hands back, why a plain variable never updates the page, ternaries and &&, map with keys, and the index-as-key bug that moves a typed note to the wrong task.
- React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
Watch useEffect on a timeline with real render counts: the dependency array deciding re-runs, a timer cleanup that keeps one timer alive, the leak StrictMode exposes, and two effects you should delete (a copied total and a click flag).
- Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
A task board where the filter is stuck in one component, fixed by lifting it to App. Then useRef as a box React does not watch (three clicks, zero renders), a ref that refocuses an input, and the tree React DevTools shows.
- Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
Four versions of an add-task form, traced with real logs: a controlled input, a classic onSubmit, a form action that gets FormData and resets itself, and useActionState with a pending button from useFormStatus, plus the draft trick that keeps typed text after an error.
- React Context and Custom Hooks: Share One Value, Reuse the Logic
Replace three hops of prop drilling with a context, see the nearest Provider win, count which components re-render on a theme toggle, then pull localStorage logic into a useLocalStorage hook and break the rules of hooks on purpose.
Working with APIs
- Server State With TanStack Query: One Key, One Request, One Cache
Three components need the same list of books. Fetch it by hand and you get three requests; ask TanStack Query for one key and you get one. With real request counts, retries and a quiet refetch on tab focus.
- Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
Add a book with useMutation and let invalidateQueries refetch the list, then make delete instant: snapshot, remove the row in 3 ms, roll back on a 404 and refetch the truth in onSettled.
- Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
Let the API's OpenAPI spec write your React client: Orval turns /v3/api-docs into TypeScript types, useGetBooks and a Zod schema, and a renamed field becomes error TS2339 at BookList.tsx line 26.
- A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
Build the React screen before the API exists: Orval writes MSW handlers and faker data from the spec, a service worker answers GET /api/books inside the browser, and npm run dev:real switches back to the real server.
- A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
Generate a React client from FastAPI's /openapi.json, then hit the CORS wall: the API answers 200 but the browser blocks it. Fix it with CORSMiddleware, or avoid it with the Vite proxy and one VITE_API_URL variable.
- Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
A book form that runs the API's own rules (a Zod schema generated from the spec) in the browser, sends nothing when pages is 0, and shows the server's 400 'title is required' under the Title field with setError.
- JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
A React app logs in to a FastAPI Helpdesk API, keeps the JWT in memory, stamps Authorization: Bearer on every call from one fetcher, guards pages with RequireAuth, and reacts to the server's 401 and 403.
