Component and container separation
The rule I follow in every React codebase: presentational components don’t fetch data, and data components don’t own markup.
- Presentational components take props and render. They are easy to test, reuse and review visually.
- Containers (or, in the App Router, Server Components and hooks) fetch, transform and pass data down.
This keeps a seller dashboard’s order table, for example, reusable whether its rows come from a GraphQL query, a REST endpoint or a test fixture.
React islands in static sites
On static sites, I hydrate React only for components that need it. On this portfolio, the project browser and the skills tabs are React islands; everything else is server-rendered HTML with no client framework at all. The page stays fast, and the interactive parts still get React’s component model.
State boundaries I keep consistent
| Kind of state | Where it lives |
|---|---|
| Server data (orders, products, users) | TanStack Query cache or Server Components |
| Cross-cutting UI state (session, cart, filters shared across pages) | Redux Toolkit or Zustand, kept small |
| Local UI state (open menu, input value) | useState in the component that owns it |
| URL state (search, pagination, selected tab) | The URL, so it’s shareable and crawlable |
Illustrative example: a container and a view
// Container: knows where data comes from
export function OrdersPanel() {
const { data, isPending, error } = useOrders({ status: "open" });
if (error) return <ErrorState retry />;
return <OrdersTable rows={data ?? []} loading={isPending} />;
}
// View: pure props in, markup out
export function OrdersTable({ rows, loading }: { rows: Order[]; loading: boolean }) {
/* ...table markup only... */
}