@moult/react
v0.1.2
Published
React adapter for committed, generation-scoped Moult contributions.
Maintainers
Readme
@moult/react
React bindings for committed, generation-scoped Moult contributions.
Installation
npm install @moult/react @moult/runtime react react-domRequires Node.js 22 or newer and React 18 or newer.
Example
RuntimeProvider exposes only committed contribution snapshots. A failed
replacement cannot render staged values.
import { createElement } from 'react';
import { createRoot } from 'react-dom/client';
import { createRuntime } from '@moult/runtime';
import { RuntimeProvider, reactWidget, useContributions } from '@moult/react';
const runtime = createRuntime();
runtime.install({
id: 'welcome',
version: '1.0.0',
setup: (context) => {
context.contribute(reactWidget, {
component: () => createElement('strong', null, 'Hello from Moult'),
});
},
});
await runtime.start('welcome');
function Widgets() {
const widgets = useContributions(reactWidget);
return createElement(
'div',
null,
widgets.map((widget, index) => createElement(widget.component, { key: index })),
);
}
const rootElement = document.getElementById('root');
if (rootElement === null) throw new Error('missing #root element');
createRoot(rootElement).render(createElement(RuntimeProvider, { runtime }, createElement(Widgets)));Features
RuntimeProviderpublishes committed runtime snapshots to React.useContributionsreads values for a typed contribution key.useContributionEntriesalso exposes generation ownership metadata.reactRouteandreactWidgetprovide standard contribution keys.ContributionErrorBoundaryisolates a contribution's render failure.guardGenerationCallbackprevents callbacks from acting after disposal or replacement.
React component state is not promised to survive generation replacement. Durable application state belongs in a host-provided capability.
Public API
The package exports RuntimeProvider, useContributions,
useContributionEntries, ContributionErrorBoundary,
guardGenerationCallback, reactRoute, reactWidget, and their public prop
and contribution types.
Status and documentation
Implemented and published. See the Moult repository, the adapter design, and the lifecycle guarantees.
