Prompt
How do I set up a headless CMS for a React app and a marketing site?
Latest observation
A good setup is:
- Headless CMS for content editing
- React app for the product/app UI
- Marketing site for public pages, SEO, landing pages, blog, docs, etc.
1) Pick a headless CMS
Common choices:
- Sanity — very flexible, great editor experience
- Contentful — polished, enterprise-friendly
- Strapi — self-hosted, full control
- Directus — good if you already have a SQL database
- Prismic / Storyblok — strong for marketing sites and page builders
If you want fast setup for both app content and marketing pages, Sanity or Contentful are usually easiest.
2) Decide what content each surface needs
Split content by use case:
React app content
Use CMS for things like:
- onboarding copy
- feature flags / announcements
- FAQs
- help articles
- CMS-driven settings
- user-facing messaging
Marketing site content
Use CMS for:
- homepage sections
- landing pages
- blog posts
- case studies
- testimonials
- pricing page content
- SEO metadata
A useful pattern is to model content as reusable blocks:
- hero
- CTA
- feature grid
- FAQ
- testimonials
- rich text sections
3) Model your content types
Example content models:
For the marketing site
page- title
- slug
- sections[]
- SEO fields
post- title
- slug
- body
- author
- publish date
testimonialsiteSettings
For the app
announcementfaqcopyBlockhelpArticle
Keep shared content in shared types when possible.
4) Set up the CMS
Example with Sanity
- Create a Sanity project
- Define schemas for your content types
- Set roles/permissions for editors
- Add preview URLs for local/staging
- Deploy the Studio
Example with Strapi
- Create Strapi project
- Create collection types and single types
- Set up API tokens and permissions
- Configure media uploads
- Deploy to a server or platform like Render/Fly/Heroku-style hosting
5) Connect the CMS to your React app
In React:
- fetch content from the CMS API
- render CMS blocks/components
- use caching to reduce requests
Typical pattern:
- create a
cmsClient - create page components that map CMS sections to React components
- use environment variables for API keys and endpoints
Example flow:
- CMS returns a page with sections
- React maps each section to a component
- Components render based on section type
6) Build the marketing site with SEO in mind
The marketing site should usually use:
- Next.js or another SSR/SSG framework
- static generation for fast loading and SEO
- CMS content fetched at build time or on revalidation
Best practice:
- use static generation for most pages
- use incremental revalidation or webhook-triggered rebuilds when content changes
- store meta title, description, Open Graph image, canonical URL in CMS
If your marketing site is separate from the app, Next.js is a common choice.
7) Use webhooks for publishing
When content changes in the CMS:
- trigger a rebuild of the marketing site
- or trigger revalidation of specific pages
This keeps content fresh without manual deploys.
8) Set up previews
Editors usually want to preview changes before publishing.
Do this by:
- having a preview environment
- reading draft content in preview mode
- using a secret token for draft access
- showing “Preview” links from the CMS to your site
9) Handle authentication and security
- Keep private tokens on the server only
- Use public read-only endpoints where needed
- Restrict write access to CMS users
- Separate staging and production environments
- Validate content before rendering
10) Recommended architecture
A common, clean setup:
- CMS: Sanity / Contentful / Strapi
- Marketing site: Next.js
- React app: React or Next.js
- Shared design system: component library used by both
- API layer: fetch CMS content server-side where possible
If both the app and marketing site are in the same codebase, you can share:
- CMS client
- content types
- UI components
- validation logic
11) Suggested implementation path
If you want to move quickly:
- Choose CMS
- Define content models
- Build marketing pages first
- Add preview and publishing flow
- Connect React app for app-specific content
- Add caching/revalidation
- Deploy and test editor workflow
12) A practical stack recommendation
If you want an opinionated stack:
- CMS: Sanity
- Marketing site: Next.js
- Product app: React or Next.js
- Hosting: Vercel
- Images: Sanity image pipeline or Cloudinary
- Auth: app-specific, separate from CMS
This gives you:
- strong editor UX
- good preview support
- good SEO
- fast iteration
If you want, I can also give you:
- a step-by-step setup with Sanity + Next.js, or
- a content model example for a marketing site and React app.