@cmssy/react

中文文档
19.30.0发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 7164

React blocks, renderers, data client and editor bridge for cmssy headless sites

原始使用文档
文档目录6 节
  1. Define a block
  2. Render published content
  3. Fetch data
  4. Live editor (client)
  5. Versioning: this package, not the API
  6. License

@cmssy/react

React building blocks for a cmssy headless site: define blocks, render published content, fetch data from the public delivery API, and drive the live editor bridge. Framework-agnostic React; for Next.js App Router wiring use @cmssy/next.

pnpm add @cmssy/react

Define a block

A block is a plain React component plus a field schema the editor reads.

import { defineBlock, fields } from "@cmssy/react";
import Hero from "./Hero";

export const heroBlock = defineBlock({
  type: "hero",
  label: "Hero",
  component: Hero,
  props: {
    heading: fields.singleLine({ label: "Heading", required: true }),
    subheading: fields.multiLine({ label: "Subheading" }),
    cta: fields.link({ label: "CTA" }),
    image: fields.media({ label: "Image" }),
  },
});

fields covers singleLine, multiLine, link, media, boolean, repeater, and more. The block component receives { content } resolved from the CMS at runtime.

Render published content

import { fetchPage, CmssyServerPage } from "@cmssy/react";

const page = await fetchPage(
  { org: "acme-org", workspaceSlug: "acme" },
  pathSegments,
);

return <CmssyServerPage page={page} blocks={blocks} locale="en" />;

CmssyServerLayout renders header/footer layout groups the same way. Both are Server Components — no block JavaScript ships to the client unless a block needs it.

Fetch data

One generic GraphQL client over the public API — write your own queries (or use the exported documents):

import { createCmssyClient, MODEL_RECORDS_QUERY } from "@cmssy/react";

const cmssy = createCmssyClient({ org: "acme-org", workspaceSlug: "acme" });

// raw query (you own scoping)
await cmssy.query(MY_QUERY, vars);

// workspace-scoped (auto x-workspace-id header + $workspaceId var)
const {
  public: {
    model: { records },
  },
} = await cmssy.queryScoped(MODEL_RECORDS_QUERY, {
  modelSlug: "posts",
});

Ready-made documents + result types: SITE_CONFIG_QUERY, MODEL_DEFINITIONS_QUERY, MODEL_RECORDS_QUERY, FORM_QUERY, SUBMIT_FORM_MUTATION.

Live editor (client)

@cmssy/react/client exposes the lazy editor + layout wrappers that keep block chunks isolated:

"use client";
import { CmssyLazyEditor } from "@cmssy/react/client";

export const CmssyEditor = (props) => (
  <CmssyLazyEditor {...props} load={() => import("./blocks")} />
);

The editor talks to the cmssy admin over the cmssy:* bridge protocol for live preview.

Versioning: this package, not the API

Pinning this package does not pin the API it talks to. The package version covers this client - its exports and their behaviour, normal semver. The cmssy delivery API is a hosted service whose GraphQL schema can change on any deploy, without a release here.

There is no dated API version to pin; the delivery endpoint has no version segment. What protects you today is that a breaking schema change cannot merge silently - it is caught by a gate that validates the SDK's own operations, and shipping one anyway takes a recorded approval - and that fields we intend to remove are marked @deprecated first. There is no guaranteed deprecation window and no minimum notice period. Details in @cmssy/core.

License

MIT

版本与发布记录

@cmssy/react 共发布 222 个版本,首次发布于 2026/06/07;过去 12 个月发布了 222 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
19.30.0latest2026/11/063 天前
19.29.02026/11/045 天前
19.28.12026/11/045 天前
19.28.02026/11/045 天前
19.27.02026/10/319 天前
19.26.32026/10/3010 天前

关于 @cmssy/react 的常见问题

@cmssy/react 是什么?

React blocks, renderers, data client and editor bridge for cmssy headless sites

如何安装 @cmssy/react?

在项目目录运行 npm install @cmssy/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.2.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cmssy/react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cmssy/react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cmssy/react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cmssy/react 可以商用吗?

@cmssy/react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cmssy/react 的下载量有多少?

根据 npm 官方下载统计,@cmssy/react 在 2026/10/10 – 2026/11/08 这 30 天内被下载 7,164 次,日均约 239 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cmssy/react 还在维护吗?

最新版本 19.30.0 发布于 2026/11/06(3 天前);至今共发布 222 个版本,其中过去 12 个月发布了 222 个;首次发布于 2026/06/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。