React Overview: From JSX to Component Architecture
A complete walk through React the way I teach it today – from declarative rendering through the question of who owns a piece of state to the architecture of a growing application. The details of individual stops will follow later as separate posts.
React Overview: From JSX to Component Architecture
React takes rendering off your hands, not architecture. The library computes a UI from a state and writes the differences to the DOM – but where this state lives, how long it lives and who may change it is something it never decides. Right there, at this inconspicuous boundary, the problems arise that you can no longer clean up later with any hook or library.
That’s why this post goes through React in one go – from the first piece of JSX to the point where individual components turn into a system. It is deliberately an overview. For most of the stops I only touch on briefly here, separate posts that dig deeper will follow. Today the goal is to have the big picture in your head before you get lost in a detail.
I rely on two repositories that I’m currently merging: introduction-react for the fundamentals and advanced-react for the advanced patterns. Neither is a slide deck in text form; both are runnable code that we practice on together. The version I describe here is React 19 – the stable release from late 2024, with everything that has become everyday practice since.
The mental model: the UI is a function of state#
Before a single line of JSX makes sense, one idea has to sink in. React flips the way you think about a UI. Instead of describing step by step how the DOM should change – insert an element here, change an attribute there, remove a node over there –, you only describe what the UI should look like for a given state. React takes care of getting there.
You can put this into a single sentence that carries everything else: the UI is a function of state. When the state changes, React calls the function again, compares the result with the previous one and writes only the actual differences to the real DOM. This reconciliation runs on an internal, lightweight representation of the tree, often called the Virtual DOM. The name matters less than the consequence: you describe the destination, not the route. I show how this reconciliation works step by step in detail in the post How React Renders and Updates the Tree.
flowchart LR State["State"] --> Render["Component renders"] Render --> View["Described UI"] View --> DOM["React reconciles and writes to the DOM"] User["User interaction"] --> Event["Event / setState"] Event --> State
The second load-bearing idea is unidirectional data flow. Data flows from top to bottom, from the parent component to the child, via props. Events flow in the other direction, upward as callbacks. There is no mysterious two-way binding in which an input field and a variable magically stay in sync. At first this feels more cumbersome than in older frameworks, but it is the reason React applications can still be explained after two years: for every spot in the UI, you can say where its data comes from and who may change it.
JSX and components: the smallest unit is a function#
JSX looks like HTML inside JavaScript, but it’s just a convenient notation for function calls. A <button> becomes a call that describes an object; it doesn’t create a DOM element. That’s why you can compute, map lists and render conditionally right in the middle of JSX – it’s all just JavaScript, after all:
function InvoiceList({ invoices }) {
if (invoices.length === 0) return <p>No invoices.</p>;
return (
<ul>
{invoices.map((i) => (
<li key={i.id}>
{i.number} - {i.paid ? "paid" : "open"}
</li>
))}
</ul>
);
}
Three details in this small example are actually architecture topics. The key attribute is not a cosmetic detail but the information React uses when re-rendering to recognize which list item corresponds to which. Conditional rendering with ? or with an early return is where loading, error and empty states become visible – exactly the states that tend to get swept under the rug in demo mode and then are missing in production. And props is a read-only interface: a component gets its data from outside and must not change it. This turns components into building blocks whose behavior you can understand from the outside. I cover the exact rules of JSX – what an expression is, what disappears during rendering, how keys really work – in detail in the post JSX Precisely: The Rules Behind the Markup.
The standard today is the functional component. It is a function that takes props and returns JSX, and with hooks it can now do everything you used to need classes for. Class components with a render method and lifecycle methods like componentDidMount still exist, and you run into them in older code. If you come across them in a grown project, there’s no need to panic – they are a historical layer, nothing more. But new code is written with functions. This is not a matter of fashion but a real simplification: an Effect that should do something on mount and on unmount used to be scattered across two separate lifecycle methods. Today it lives in one place.
Composition replaces inheritance. Instead of extending a base component, you nest components inside each other and pass content through via children:
function Card({ title, children }) {
return (
<section className="card">
<h2>{title}</h2>
{children}
</section>
);
}
A Card like this knows nothing about its content and is usable everywhere precisely because of that. Once you internalize this reflex – compose rather than inherit –, you write decoupled UIs almost automatically.
State is not a place#
Now comes the question from the beginning, and it is the most important one in this whole post. State is not a place in the code but a decision about ownership, lifetime and synchronization. Before you write useState, you should know who this state actually belongs to.
The local case is the simplest. A counter, an expanded menu, the text in an input field – state like this belongs in the component that displays it:
import { useState } from "react";
function Counter({ start = 0 }) {
const [count, setCount] = useState(start);
return <button onClick={() => setCount((n) => n + 1)}>{count}</button>;
}
The rule React demands at this point is: keep components pure. The same inputs should produce the same output. The state isn’t mutated directly but replaced via the setter function, and React decides when to re-render. If you take this seriously, you get components you can play through in your head without a running browser.
It gets interesting as soon as a piece of state no longer fits into a single component. Then you have to answer honestly where it belongs, and the answer is rarely “in a global store”. I distinguish four places, and choosing between them is the real architecture work in the frontend:
flowchart TB Frage["Who owns this state?"] Frage --> Lokal["Component<br/>(useState) – UI detail"] Frage --> URL["URL<br/>filter, page, selected object"] Frage --> Server["Server cache<br/>loaded data that belongs to the backend"] Frage --> Global["Global store<br/>app-wide, shared decisions"]
Much of what teams reflexively put into a global store actually belongs in the URL – which filter is active, which page is shown, which object is selected. In the URL, this state is shareable, can be saved as a bookmark and survives a reload. And a large part of what looks like application state isn’t state at all: it is data that belongs to the server and that you have merely cached. This distinction between real client state and cached server data is the most consequential one in the entire frontend, and I dedicate a separate post to it: Client state vs. server cache.
Effects are the edge, not the center#
useEffect is the hook that has caused the most misunderstandings in the teams I’ve worked with. It synchronizes a component with something outside of React – a network call, a subscription, the title of the browser tab, a timer. The key sentence is: an Effect is the edge of the system, not its center. Anything you can compute from state doesn’t belong in an Effect but directly in rendering.
import { useState, useEffect } from "react";
function useInvoice(id) {
const [data, setData] = useState(null);
const [error, setError] = useState(null);
useEffect(() => {
let active = true;
fetch(`/api/invoices/${id}`)
.then((r) => r.json())
.then((d) => active && setData(d))
.catch((e) => active && setError(e.message));
return () => {
active = false;
};
}, [id]);
return { data, error };
}
Two things about this example are the real lesson. The dependency array [id] determines when the Effect runs again – if you forget a value there, the component keeps working with stale data. And the returned cleanup function, which sets active to false, prevents a late-arriving response from overwriting the state of a component that has already unmounted or of a request that has since been superseded. This race between two requests is exactly the bug that never shows up in tests with fast responses and only strikes in production on a slow network.
I deliberately pulled the logic here into its own custom hook useInvoice. That already brings us to today’s way of reusing logic – more on that in a moment. All that matters at this point is the mindset: limit Effects, don’t pile them up. A frontend in which data loading, derivation, synchronization and user events all end up in a single lump of Effects is fragile, because nobody can say anymore why which Effect runs when.
The most common mistake I see in code reviews is exactly the opposite reflex: mirroring a value that can be computed from other state into a second state via an Effect. If you write the full name from first and last name into its own variable via an Effect, you have built yourself two sources of truth that drift apart as soon as a render gets in between. The computed value doesn’t belong in an Effect, nor in a second useState, but simply in rendering, where it is created fresh on every pass. What can be derived is derived, not stored – this one rule saves you more bugs than any library. An Effect is only justified when something outside of React is really involved.
By the way, for loading server data you rarely have to write this mechanism by hand in real projects. In practice, a library specialized for this handles caching, refetching and consistency. React 19 goes one step further with the use() hook and Suspense and lets you await a Promise directly during rendering, so loading and error states move further out to an enclosing <Suspense> component. I cover this big topic of its own in the post Suspense and the use Hook.
From HOCs and render props to custom Hooks#
The advanced React patterns, which form their own block in the advanced-react material, are almost all answers to the same question: how do I share logic between components without copying it? The answer has shifted over the years, and this shift is instructive in itself.
There used to be two established patterns for this. A higher-order component is a function that takes a component and returns an enhanced one – a wrapper that adds behavior. Render props solve the same problem by having a component expose its logic through a function as its child. Both work, but both come at the same price: they nest the component tree and turn a flat idea into a deep structure.
Custom Hooks solve exactly this problem without nesting the tree. A custom hook is simply a function whose name starts with use and that uses other hooks. The useInvoice from above is already one. The logic lives in a normal function, is called by several components and doesn’t show up in the tree at all:
function InvoiceView({ id }) {
const { data, error } = useInvoice(id);
if (error) return <ErrorMessage text={error} />;
if (!data) return <LoadingIndicator />;
return <InvoiceDetails invoice={data} />;
}
You find the same movement with context. Passing data down through many levels without threading it as a prop through every intermediate component is the job of context: a provider at the top of the tree, a useContext further down. The important caveat: context is meant for distributing, not as a replacement for well-thought-out state ownership. If you put every changing value into a context, you only move the coupling problem one level up. I cover this too – context as a distribution channel versus context as hidden global state – in the post Using Context well.
When shared state really is global: Redux and the alternatives#
Sometimes state really is app-wide and is read and changed by many places far apart from each other. There are established tools for this case, and Redux is the best known. Its core is surprisingly small: the entire state lives in one store, it is changed only by dispatching an action – a plain object with a type –, and a reducer is a pure function that computes the new state from the old state and the action.
function invoicesReducer(state = [], action) {
switch (action.type) {
case "invoice/paid":
return state.map((i) =>
i.id === action.id ? { ...i, paid: true } : i
);
default:
return state;
}
}
The appeal of this pattern is that every state change becomes a named, loggable event. You can trace the sequence of actions, record it and replay it in a test. The price is a certain amount of structure. In projects I have come across three ways to organize this structure, and the choice determines whether a UI system grows along the domain or along technical lines: the Rails style with separate folders for actions, reducers and containers; the domain style, which instead bundles per feature; and the Ducks pattern, which puts the actions and reducer for one thing into a single file. The domain split is almost always the better one, because it draws file boundaries along the domain and not along technical roles.
Today hardly anyone writes Redux out by hand like this anymore. The official Redux Toolkit takes most of the repetition off your hands, and for many applications a lighter library or simply context with a reducer is enough. Reactive approaches like MobX pursue the same goal with a different model, in which derived values update automatically. Which of these tools fits depends less on fashion than on an honest answer to the ownership question from earlier – I dedicate a separate comparison to it: State Management in React: Redux Toolkit, Lightweight Stores, MobX.
In architecture discussions, I like to do the cross-check: for how much of the supposedly global state do you really need the store? Most of the time the list shrinks dramatically as soon as you use the URL for selection and filters and treat loaded server data as what it is – cache, not state. What often remains is just a small core of real, app-wide decisions: the signed-in person, the chosen language or theme setting, maybe a shopping cart. For this core a store pays off; for the rest it is dead weight. So a global store isn’t the default answer but the exception you have to be able to justify.
Router, server and the edges of the application#
Two edges are still missing. The first is navigation. In a single-page application, you don’t switch pages; you map URLs to components. The router keeps the address bar and the displayed component in sync, so the back and forward buttons, bookmarks and shared links keep working:
import { BrowserRouter, Routes, Route } from "react-router-dom";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Start />} />
<Route path="/invoices/:id" element={<InvoiceView />} />
<Route path="*" element={<NotFound />} />
</Routes>
</BrowserRouter>
);
}
This also makes the router the natural place for the state that belongs in the URL. The :id parameter, which you read in the component via useParams, is exactly the selected object I talked about above – no reason to also keep it in a store. For new projects, React Router now recommends the data router variant with createBrowserRouter, in which routes also get loading and writing functions; that is the more modern way, and I dedicate the post React Router data router to it.
The second edge is rendering on the server. For startup time, search engines and weak devices, it often makes sense to generate the first version of the page on the server and only bring it to life in the browser. Frameworks like Next.js take care of these mechanics for you. React 19 expanded the topic fundamentally once more with Server Components: components can run on the server, load data there and send only their result to the browser, while Server Actions form the counterpart for write operations. This noticeably shifts the old boundary between client and server, and it is such a big topic that I dedicate the post React Server Components and Server Actions to it; here it only serves as a signpost.
Operations: tests, toolchain, types#
An overview that stops at rendering would be incomplete, because all the boundaries I have described – state ownership, Effect discipline, data flow – can break unnoticed if nobody pins down an expectation about them. In the frontend, tests are not a chore but the place where these expectations stay visible.
Today I test components with Vitest and the React Testing Library, and its guiding idea fits the architecture of this post exactly: you check what users see and do, not how the component is built inside. A test tied to the visible result survives a refactoring; a test glued to implementation details breaks with every rename.
import { describe, it, expect } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Counter } from "./Counter";
describe("Counter", () => {
it("counts up on click", async () => {
render(<Counter start={0} />);
const button = screen.getByRole("button", { name: "0" });
await userEvent.click(button);
expect(screen.getByRole("button", { name: "1" })).toBeInTheDocument();
});
});
Behind this is the same test pyramid as everywhere: many fast component tests at the base, fewer integration tests in the middle, a handful of end-to-end tests with a tool like Playwright at the top. If you turn this distribution upside down, you pay for it later with a sluggish build pipeline.
The toolchain is an architecture decision too, not a matter of taste. Whether a project starts with Vite, Next.js, Parcel or a handwritten webpack configuration determines how fast the feedback is during development, how easy server rendering becomes and how much you maintain yourself. And on top of all this sits TypeScript, which turns props and state into checkable contracts. A mistyped prop then doesn’t become a runtime error for the user but a red squiggle in the editor. Finally, the React Compiler, which the React team develops as a separate project alongside the library, takes over part of the manual optimization: it analyzes components at build time and automatically remembers what hasn’t changed between two render passes, so many calls to useMemo, useCallback and memo become unnecessary.
The repository is already architecture#
One last look at the structure of the repositories themselves. introduction-react and advanced-react aren’t one big lump but many small, self-contained examples – a basic app, a Redux app, a router app, one with server rendering, plus the advanced folders for asynchronous patterns, functional composition and structure. Each example stands on its own and can be started individually.
The fact that I’m currently merging the two repositories is therefore a small architecture exercise in itself. The question is the same as for any growing system: what may be shared, and what has to stay separate so that a change in one place doesn’t unexpectedly break something in another? A cleanly split monorepo of fundamentals and advanced examples solves exactly the same task as an application made up of many components and modules. In both places, the boundaries you draw are the real work.
flowchart TB Repo["React monorepo"] Repo --> Grund["Basics<br/>JSX, components, hooks, router"] Repo --> Fort["Advanced<br/>async, functional, structure"] Repo --> Geteilt["Shared building blocks<br/>UI components, test helpers"] Grund --> Geteilt Fort --> Geteilt
What should stick in the end#
At best, what remains from a walk-through like this is not the sentence “I know the hooks now” but a reflex: for every piece of state, first ask who owns it and how long it should live. That is exactly the core. React gives you a very good tool for describing UIs, but it doesn’t make the architecture decisions for you. Who owns a piece of state, where an Effect has its edge, which state lives in the URL, in the server cache or in the store – that remains the work a human has to do.
That’s why this post is an overview and not a handbook. I only briefly touched on many stops: the difference between client state and server cache, context as a distribution channel, the choice between Redux and its lighter alternatives, Suspense and Server Components, testing without theater. There is more to say about each of these stops than an overview can carry, and that is exactly the plan: the details will follow as separate posts, each with a concrete example and at least one failure case. Once you have the big picture in your head, you’ll know where you currently stand.
Further reading#
- Repository introduction-react (fundamentals): https://github.com/mikebild/introduction-react
- Repository advanced-react (advanced patterns): https://github.com/mikebild/advanced-react
- Slide overview for this overview: https://slides.mikebild.dev/introduction-react.en.html
- React, official documentation (Thinking in React): https://react.dev/learn/thinking-in-react
- React 19, announcement of the stable release: https://react.dev/blog/2024/12/05/react-19
- React, managing and sharing state: https://react.dev/learn/managing-state
Revised and translated from German with the help of AI.