M0rphicComponent

Render AI-generated components from the component library with dynamic data binding and event handlers.

Note

M0rphicComponent loads and renders published components created in the Dashboard. It supports placeholder data binding and event handler registration.

Basic Usage

Load a component by ID and bind data and handlers:

typescript

Props

PropTypeDefaultDescription
componentId*string-The unique ID of the published component from the Dashboard.
dataRecord<string, unknown>-Object with values to replace ${data.xxx} placeholders in the component.
handlersHandlerMap-Event handlers that can be triggered by the component (e.g., onClick, onSubmit).
customRegistryRecord<string, ComponentType>-Custom React components to extend the default rendering registry.
fallbackReact.ReactNode-Content to display while the component is loading.
errorComponentComponentType<{ error, retry }>-Custom component to render when loading fails. Receives error and retry props.
classNamestring-Additional CSS class name for the wrapper element.
onLoad(jsx: JSXElement) => void-Callback fired when the component loads successfully.
onError(error: Error) => void-Callback fired when loading fails.

Data Binding

Replace placeholders in the component with dynamic values. Supports nested paths like ${data.user.name}.

typescript

Tip

Placeholder names are suggested by AI when you create the component. Click the $ button in edit mode to insert placeholders.

Event Handlers

Bind JavaScript functions to events defined in the component. Handler names are set when creating the component in the Dashboard.

typescript

Loading & Error States

Customize the loading and error experience for better UX:

typescript

useM0rphicComponent Hook

For more control over the component lifecycle, use the hook directly:

typescript

Hook Return Values

PropTypeDefaultDescription
jsxJSXElement | null-The parsed JSXElement with data bindings applied, or null if not loaded.
isLoadingboolean-True while fetching the component from the server.
errorError | null-Error object if loading failed, null otherwise.
render() => React.ReactNode-Function that renders the component with handlers applied.
refetch() => void-Function to reload the component from the server.

Workflow

1
Create in Dashboard

Use AI to generate a component in the Dashboard's Component Library.

2
Add Placeholders

In edit mode, click $ to mark text as dynamic (e.g., ${data.title}).

3
Publish

Publish the component to make it available via the API.

4
Render in App

Use M0rphicComponent with data and handlers to render it in your app.

Component Types Comparison

Choose the right component based on your use case:

FeatureM0rphicComponentM0rphicZoneM0rphicStreamZone
Use CaseRender pre-built AI componentsLayout orchestration with A/B testingReal-time AI generation
SourceDashboard Component LibraryPre-registered React componentsAI generates on-demand
Data Binding✓ ${data.xxx}✗ Props only✗ Prompt context