Skip to content

React + Payload: my most-used stack

This is the stack I reach for when someone needs a website with content they can edit themselves. Here is how it's built, and what I've learned from running it in production.

Typically it's a company site, a campaign page or the front of a webshop. React on the frontend, Payload CMS on the backend, both written in TypeScript and kept in one monorepo. The site you're reading this on runs on it too, so most of the examples below come straight from gearloose.dk.

This post is long because I want to show more than a list of benefits. I go through how the project is structured, what happens from the moment a visitor opens a page until the HTML is in their browser, how an editor's change reaches the site, and which mistakes I've hit in production. At the end there's a checklist and a section on when I'd pick something else.

Why this combination

Payload is a headless CMS where the content model is code. Collections, fields, access rules and translations are defined in TypeScript and live in git with the rest of the project. When I add a field to a case, it's a change to a file that gets reviewed, committed and deployed like any other code. Nobody has clicked together a content model in an admin panel that no one else can recreate.

That has three consequences I value:

  • The content model has history. The git log shows when a field was added, and why.
  • A new environment is a copy of the code. A local development database, a test environment and production get the same collections, because they're built from the same files.
  • The data sits in an ordinary Postgres database. The client doesn't pay a licence per editor, and there's no export button you have to hope works the day you want to move. The database can be dumped, restored and queried with ordinary tools.

React on the frontend gives me the freedom to build exactly the experience the project needs. There are no theme limitations, and nothing I have to ask a plugin's permission for.

How the project is structured

gearloose.dk is a pnpm monorepo with three parts:

  • apps/cms is Payload 3 with the Postgres adapter and Lexical as the rich text editor. The admin panel runs on Next, because that's how Payload 3 is built.
  • apps/web is React 19 with Vite, Tailwind, TanStack Query and React Router 7.
  • packages/shared holds the types and interfaces the frontend works with.

There's no Turborepo or other build orchestration. Root scripts call pnpm --filter on whichever app needs building or running. That's enough for a project of this size, and it's one less thing for the next developer to learn.

The frontend doesn't know about Payload

The most important architecture decision is that the React components never see a raw response from Payload. Payload generates its own TypeScript types, but they're only used inside the CMS. Instead, the frontend depends on:

  • My own view models in packages/shared, such as a BlogPostModel, with exactly the fields a page needs.
  • A `ContentRepository` interface describing what the frontend can ask for: a page, a list of cases, a blog post.
  • A Payload adapter that implements the interface. It's an HTTP client plus a set of small mappers that translate Payload's JSON into the view models.

It's classic ports and adapters, and it may sound like a lot of ceremony for a website. The payoff shows up when something changes. When I adopted Payload's SEO plugin, the title and description moved from two loose fields into a meta group. The change lived in one mapper, which now reads meta first and falls back to the old fields. No component was touched. The same pattern made it possible to move content off WordPress without rewriting the frontend, because the frontend never knew where the data came from.

The content model

Content is split by what it is, not by how it looks: pages built from blocks, cases, packages, services, partners, tech stacks and blog posts, plus globals for the header, footer, contact page and site-wide defaults. A case has rich text fields for problem, solution and result, a gallery and a testimonial. A blog post has a title, slug, excerpt, image, body and publish date.

That split means editors fill in fields that fit the content, and the frontend can show each type in its own way. A case page and a blog post don't look alike, and they shouldn't.

From request to finished page

gearloose.dk started as a purely client-side React app. The browser fetched an empty HTML page, ran the JavaScript and then asked Payload for the content. That's quick to build and fine for users, but a crawler that doesn't run JavaScript just saw an empty <div id="root">. For a site whose job is to be found, that wasn't good enough.

So I moved the site to React Router 7 in framework mode with server rendering enabled, behind a small Express server. Today a request looks like this:

  1. A visitor, or Google, asks for, say, /cases/luggage-log.
  2. The Express server matches the route, and the route's loader runs.
  3. The loader creates a new TanStack QueryClient for that one request and fetches the data the page needs from Payload's REST API.
  4. React renders the page to HTML on the server, and the title, description, canonical and language tags are set from the CMS fields.
  5. The HTML is sent to the browser along with the "dehydrated" query state, meaning the data the server has already fetched.
  6. In the browser, React takes over the page without fetching the same data again, and navigation from there happens client-side.

The new QueryClient per request matters. If one client is shared between all requests on the server, one visitor's data can end up in someone else's page. For the same reason, the language is bound to the individual HTTP client rather than stored globally. When two visitors hit the server at the same time, one in Danish and one in English, each gets their own language.

The switch to server rendering also brought a number of things that were hard before:

  • Real 404s. A page that doesn't exist now answers with status code 404, not a 200 with a "not found" message.
  • Language tags (hreflang) on every page, so search engines know the Danish and English versions belong together.
  • robots.txt and a sitemap, generated straight from the content in the CMS. When an editor creates a new case, it lands in the sitemap without a deploy.
  • Old WordPress addresses are redirected inside the app, so links to the old site still work.
  • The preview domain is noindex, so the test version of the site doesn't compete with the real one in search results.

Prerendering as an alternative

Server rendering isn't the only answer. NaturRo uses a different approach: the frontend is a plain Vite app with no server, and on every build a headless Chromium driven by Playwright visits every static page and every trip and saves the finished HTML. The same build writes the sitemap and an llms.txt.

That's simpler to run, since there's no Node server in front, but it has a cost: a change in the CMS needs a new build before the static HTML is updated. For a site where content doesn't change every minute, that's a fair trade. For gearloose.dk, where I wanted pages and the sitemap updated the moment something is published, I chose server rendering.

From an editor's change to the site

Because pages are rendered on every request, the path from an edit to a visible result is short:

  1. The editor logs into the admin panel and edits a blog post, a case or a page.
  2. On collections with drafts enabled, the change is saved as a draft until they hit publish. Blog posts and cases have versions, so an earlier version can be restored.
  3. Once the content is published, the next request shows the new version. There's no build or deploy in between.

Structural changes take a different route. A new field or a new block is a code change that goes through git, a migration and a deploy. That split is deliberate: editors change content whenever they like, and a developer changes structure, with review.

Localization

The site exists in Danish and English. Danish is the default, and when a translation is missing, Payload falls back to the Danish text instead of showing an empty field. Almost every text field is marked as translatable, while things like slugs are shared between languages, so a case has the same address in Danish and English, just with /en in front.

Localization was added after the site was built. It needed a migration that copied the existing content over as the Danish version, and that migration had to be reworked so it could run more than once without doing damage. If you know from the start that a site will have two languages, turn it on from day one.

SEO fields

Payload's official SEO plugin is enabled on pages, cases, packages and blog posts. It gives editors an SEO tab with a title, description and share image, a preview of how the page looks in search results, and buttons that suggest a title and description from the content's own title and excerpt. The plugin also shows whether the title and description are a sensible length.

When the plugin went in, the pages already had SEO titles in two older fields. A migration copied them into the new fields, but only where the new ones were empty, and the old fields were kept as a fallback until I'd seen the new content on the live site.

Where I've used it

  • gearloose.dk. Cases, packages, services, blog and pages in Payload, server-rendered React in front, Danish and English, deployed on my own server via Coolify.
  • [NaturRo](/en/cases/naturro-hjemmeside-og-grafisk-identitet). Payload drives all the content about the hiking trips, the frontend is prerendered for SEO, and Medusa handles booking and payment. That part has its own post.
  • [Luggage Log](/en/cases/luggage-log). The landing page follows the same pattern with server rendering, Danish and English, the SEO plugin, and terms, support and privacy policy as CMS content, so they can be edited without a deploy. It's kept separate from the app itself, because a marketing site has different needs than a product.
  • [Kyst-Ild-Vildt](/en/cases/kyst-ild-vildt). A booking site for full-day experiences, with the content managed in Payload.

The benefit of reusing the same pattern is that a fix found on one project can move to the next almost unchanged. Several of the operational fixes on Luggage Log's landing page are more or less the same commits as on gearloose.dk.

Lessons from production

Most of this isn't about React or Payload as such. It's about everything that happens around them when they have to run reliably on a server.

Migrations

  • Migrations are code. When a collection changes, I generate a migration and commit it with the change. In production, Payload is never allowed to "push" the schema directly. That's only enabled locally.
  • Don't trust that the migration ran. On gearloose.dk, payload migrate finished about one time in three without errors and without having done anything. Two deploys skipped migrations that way, and the CMS answered with errors because the code expected columns that didn't exist. The container's startup now retries until the migration reports that it's done, and refuses to start if it never does.
  • Migrations can wait for an answer nobody gives. On NaturRo, payload migrate hung forever on a yes/no prompt because there was no terminal to answer it. The fix was to pipe the answer in with yes | payload migrate.
  • Read the generated migration. On NaturRo, Payload generated a migration that changed a relation and, in the same go, dropped the old column without copying the data over. That's why I now rehearse risky migrations on a restored copy of the production database before they touch the real site.
  • Translated fields live somewhere else. When a field is localized, its value sits in a separate table per language. The SEO plugin's image field is localized, so it lives in the locale tables, not the main table. That matters the day you write a migration by hand.

Content

  • Seed data has to be published. Content created by a script without the status "published" exists in the admin, but is invisible on the site.
  • Drafts must be hidden in the API too. With versions enabled, read access has to make sure anonymous visitors can't fetch drafts. NaturRo learned that the hard way.
  • Rich text isn't HTML. Payload stores body text as a structured tree. The frontend has a small renderer that walks the tree and produces HTML, instead of pulling Payload's server packages into the browser.

Operations

  • A health endpoint that doesn't depend on the CMS. The frontend server has its own /healthz, so Coolify can see it's running even while the CMS restarts.
  • Keep-alive has to match the proxy. Traefik reuses connections longer than Node's default. When Node closes a connection Traefik still thinks is open, the user gets a sporadic error. So Node's timeout is set higher than Traefik's.
  • Never start a container by hand next to the real one. With two containers behind the same address, Traefik picks between them at random, and some requests fail. Everything goes through Coolify.
  • Keep an eye on dependencies. Payload 3 has tight requirements for which Next version it runs with. A lockfile that has drifted out of step shows up later as a mysterious error in a build.

Testing

Playwright runs through navigation, language switching, calls to action and the front page on both desktop and a mobile profile. A separate test checks the site's design colours and takes a full-page screenshot that's compared against an approved version. If the layout or colours drift after a change, the test fails before a user notices.

When I'd pick something else

React and Payload are my default, but not my only choice:

  • The client knows WordPress and has a team that does. Then it's often smarter to build a proper WordPress site than to move them.
  • The site is five static pages that rarely change. A CMS is overhead if nobody needs to edit anything.
  • There's nobody to look after a server. Self-hosted Payload needs updates, backups and monitoring. That's part of the price of owning your data.
  • The project is first and foremost a webshop. Then Medusa comes in alongside, as in my post on e-commerce.

Checklist for your own project

  1. Turn on localization from the start if there will ever be more than one language.
  2. Let the frontend depend on your own view models, not on the CMS's types.
  3. Choose server rendering or prerendering before you launch, not after Google has indexed an empty page.
  4. Commit migrations, and check after each deploy that they actually ran.
  5. Rehearse risky migrations on a copy of the production database.
  6. Take a backup before every change that touches data.
  7. Make sure drafts can't be fetched anonymously.
  8. Give the frontend server a health endpoint that doesn't depend on the CMS.
  9. Fill in the SEO fields on everything that needs to be found.

What you get out of it

  • You edit it yourself. Text, images, pages and SEO fields are changed in the admin without calling me.
  • No vendor lock-in. Payload runs on your own Postgres database and your own server. The data is yours.
  • Pages Google can read. Server rendering or prerendering, depending on the need.
  • Two languages from the start, if you need them.
  • Type safety end to end. Errors get caught in the build, before they hit production.

Looking for a Payload CMS developer in Denmark? Read more about how I work with Payload.

Working in the same stack?

Are you building with React and Payload yourself, or thinking about moving off WordPress or a SaaS CMS? I'm happy to share experience on migrations, localization, server rendering and self-hosting. Get in touch.