@stormycms/react
React rendering, CMS registration, editor state, and session context.
pnpm add @stormycms/react| Import | Exports |
|---|---|
@stormycms/react/cms | withCMS, ComponentTree, LayoutTree, Layout, Outlet, buildLayoutTree, findComponent |
@stormycms/react/cms/client | CMSPageProvider, CMSLayoutProvider, useCMSPage, useCMSLayout |
@stormycms/react/stormy | StormyProvider, useStormy |
@stormycms/react/plugin | React plugin for schema generation |
withCMS
withCMS(cmsProps, Component) attaches CMS metadata to a React component.
| Option | Meaning | Default |
|---|---|---|
export | Name in the component export map | Required |
label | Editor picker label | Required |
fields | CMSField[] | Required |
noChildren | Disallow child components | false |
validChildren | Allowed child names | Unrestricted |
validParents | Allowed parent names | Unrestricted |
layoutOnly | Available only in layouts | false |
editable | Show an edit form | true |
unique | One instance per parent | false |
See Components and schema for registration and Fields for controls.
Rendering
ComponentTree takes components: CMSComponentData[], cmsExports: CMSExportsMap, and optional slotContent: ReactNode. It skips names absent from the map. slotContent renders at each Outlet.
buildLayoutTree(layouts, parentLayoutId) builds a layout chain from a flat list. Pass the page's layoutId as the second argument. It returns null if it cannot find a root layout.
LayoutTree takes layout: CMSLayoutData | null, cmsExports, and children. A null layout renders children directly. Each layout's Outlet renders the next layout or the page content.
Layout renders layout components and passes children through their outlets. Outlet is a non-editable, layout-only CMS component.
findComponent(components, id) searches descendants and returns a component or null.
Editor state
CMSPageProvider takes page: { id, components, initialData: { name, slug, layoutId? } }.
CMSLayoutProvider takes layout: { id, components, initialData: { name, parentLayoutId? } }.
The corresponding hooks expose component state and helpers to add, update, and remove components. They do not save to the API.
Session context
StormyProvider supplies session and site state. In Next.js, StormyServerProvider loads initial data on the server.
| Prop | Default |
|---|---|
authUrl | /api/auth/stormy?action=session |
siteUrl | /api/auth/stormy?action=site |
sitesUrl | /api/auth/stormy?action=sites |
loginUrl | /login |
guard | true |
checkThrottleMs | 60000 |
onSessionExpired | Redirect to loginUrl when absent |
initialUser, initialSite, initialSites | null, null, [] |
The guard checks sessions on activity and tab focus. onSessionExpired replaces its expiry redirect.
useStormy() returns { user, site, sites, isLoading, isAuthenticated, refresh } and throws outside the provider. refresh() reloads site data.
Last updated: 10/20/26, 1:09 AM