Skip to main content
StormyCMS

@stormycms/react

React rendering, CMS registration, editor state, and session context.

Terminal window
pnpm add @stormycms/react
ImportExports
@stormycms/react/cmswithCMS, ComponentTree, LayoutTree, Layout, Outlet, buildLayoutTree, findComponent
@stormycms/react/cms/clientCMSPageProvider, CMSLayoutProvider, useCMSPage, useCMSLayout
@stormycms/react/stormyStormyProvider, useStormy
@stormycms/react/pluginReact plugin for schema generation

withCMS

withCMS(cmsProps, Component) attaches CMS metadata to a React component.

OptionMeaningDefault
exportName in the component export mapRequired
labelEditor picker labelRequired
fieldsCMSField[]Required
noChildrenDisallow child componentsfalse
validChildrenAllowed child namesUnrestricted
validParentsAllowed parent namesUnrestricted
layoutOnlyAvailable only in layoutsfalse
editableShow an edit formtrue
uniqueOne instance per parentfalse

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.

PropDefault
authUrl/api/auth/stormy?action=session
siteUrl/api/auth/stormy?action=site
sitesUrl/api/auth/stormy?action=sites
loginUrl/login
guardtrue
checkThrottleMs60000
onSessionExpiredRedirect to loginUrl when absent
initialUser, initialSite, initialSitesnull, 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

StormyCMS

The headless CMS where you own the editor.