DevelopersReact

React SDK

First-class React: your components, your design system, your render path

React is the RuleCMS reference SDK. Register custom libraries in the composer, server-render published widgets, preview Development drafts live, and pass host-app handlers into a single button.

Getting started guide

Install and embed

Add @rulecms/widget-react and render a published widget.

install.shBash
npm install @rulecms/widget-react
HomepageHero.tsxTSX
import { RuleCMSWidget } from "@rulecms/widget-react";export function HomepageHero() {  return (    <RuleCMSWidget      publishedKey="your-widget-key"      ...    />  );}

Why React is first-class

Other official SDKs render the default RuleCMS cards. React can also bring your own system into the CMS.

Marketers still compose visually. Developers still get JSON, environment tokens, and a published key. The difference is how far the host app can go: React is where RuleCMS already acts as a design-system CMS, not only a card renderer.

  • Register a team-scoped custom component library so your React components appear in the composer palette with attribute editing, lazy loading, and SSR.
  • Server-render with fetchRuleCMSWidget plus mode="pre-fetched", or skip widget JavaScript entirely with RuleCMSWidgetServer on React Server Components.
  • Preview live Development drafts with a dev. token — no publish step. See development integration.
  • Pass host-app click handlers and extra props by column id. See custom props and click handlers.
  • Register a component from your app by name so a Custom slot can render it. See mount your own components.
  • Open a published widget in the editor from your live site with the Chrome edit-links extension.

Environments and tokens

Development, Staging, and Production each have their own keys.

Staging and production use a plain token plus a published key shaped like environmentId---widget-…. Development uses a dev. token and a draft widget key so the composer can stream the current draft into your app. Keep tokens in server-only environment variables whenever you fetch on the server — never NEXT_PUBLIC_* for a production token.

Full walkthrough: projects, environments, and tokens.

Server render, or ship zero widget JavaScript

Two server APIs. Pick the one that matches your host.

Prefetch on the server, then hydrate in the browser. This works on Next.js App Router, Pages Router, Remix / React Router, and any React SSR host where you own the fetch:

app/page.tsxTSX
import { fetchRuleCMSWidget } from "@rulecms/widget-react/server";import { RuleCMSWidget } from "@rulecms/widget-react";export default async function Page() {  const data = await fetchRuleCMSWidget({    publishedKey: process.env.RULECMS_PUBLISHED_KEY!,    token: process.env.RULECMS_TOKEN!,    fetchOptions: { next: { revalidate: 60 } },  });  return (    <RuleCMSWidget      mode="pre-fetched"      publishedKey={process.env.RULECMS_PUBLISHED_KEY!}      initialData={data}    />  );}

On React Server Components, RuleCMSWidgetServer fetches and renders on the server. No widget JavaScript ships to the browser. If the CMS is down, the component logs and shows errorFallback — a content outage does not take your page with it.

app/page.tsxTSX
import { RuleCMSWidgetServer } from "@rulecms/widget-react/server";export default function Page() {  return (    <RuleCMSWidgetServer      publishedKey={process.env.RULECMS_PUBLISHED_KEY!}      token={process.env.RULECMS_TOKEN!}      fetchOptions={{ next: { revalidate: 60 } }}      errorFallback={<p>Content is temporarily unavailable.</p>}    />  );}

Custom libraries and design systems

This is the React-only depth other SDKs do not document.

The default cards cover a long customer journey on their own: heroes, FAQs, media, and calls to action. When your brand already lives in a React design system, register that library on the team. Editors drag your components. Published widgets render those same components in the host app, including SSR.

That is why React is first-class. Angular, Vue, Svelte, Flutter, and React Native still get official SDKs and the default card set — enough to buy, compose, publish, and ship. When you need the composer to speak your component library, React is the path that is already built.

Read the component libraries guide. For a live customer using a custom React library, see the ATL Fluid Art case study.

Host-app behavior on a single component

Address a column by the id the composer shows you.

A published widget should not own your checkout drawer or your router. Pass an onClick — or any extra prop — to one instance. A bare id matches every copy of a repeated collection. A / path of enclosing collection columns targets one embedding. Longest match wins. In development, a key that addresses no column prints once so typos show up while you build.

HomepageHero.tsxTSX
import { RuleCMSWidget } from "@rulecms/widget-react";export function HomepageHero() {  return (    <RuleCMSWidget      publishedKey="your-widget-key"      componentProps={{        "b721c4e2-…": { onClick: handleCta },        "holder-a/inner-col": { onClick: openBookingDrawer },      }}    />  );}

Packages

Install from the public registry. These are the supported SDK surfaces — not GitHub source repos.

Sample labs

Public teaching projects that show the integration pattern. Copy the wiring, not the app architecture — they are not production starters.

Next.js sample lab

Client, server, static, and incremental rendering of the same published widget.

Create React App sample lab

A client-rendered React lab for the basic embed path.

Need the product docs for tokens, widgets, or the headless API? Start at Getting started, then environments and tokens and the API reference.

Other SDKs

Same published widgets and environment tokens. Pick the guide for the stack you ship.

Explore RuleCMS

Dive deeper into what makes RuleCMS different.

Ship React with RuleCMS

Create a project, provision three environments, and copy a scoped API token.