M0rphicComponent
Render AI-generated components from the component library with dynamic data binding and event handlers.
Note
Basic Usage
Load a component by ID and bind data and handlers:
Props
| Prop | Type | Default | Description |
|---|---|---|---|
componentId* | string | - | The unique ID of the published component from the Dashboard. |
data | Record<string, unknown> | - | Object with values to replace ${data.xxx} placeholders in the component. |
handlers | HandlerMap | - | Event handlers that can be triggered by the component (e.g., onClick, onSubmit). |
customRegistry | Record<string, ComponentType> | - | Custom React components to extend the default rendering registry. |
fallback | React.ReactNode | - | Content to display while the component is loading. |
errorComponent | ComponentType<{ error, retry }> | - | Custom component to render when loading fails. Receives error and retry props. |
className | string | - | 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}.
Tip
Event Handlers
Bind JavaScript functions to events defined in the component. Handler names are set when creating the component in the Dashboard.
Loading & Error States
Customize the loading and error experience for better UX:
useM0rphicComponent Hook
For more control over the component lifecycle, use the hook directly:
Hook Return Values
| Prop | Type | Default | Description |
|---|---|---|---|
jsx | JSXElement | null | - | The parsed JSXElement with data bindings applied, or null if not loaded. |
isLoading | boolean | - | True while fetching the component from the server. |
error | Error | 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
Use AI to generate a component in the Dashboard's Component Library.
In edit mode, click $ to mark text as dynamic (e.g., ${data.title}).
Publish the component to make it available via the API.
Use M0rphicComponent with data and handlers to render it in your app.
Component Types Comparison
Choose the right component based on your use case:
| Feature | M0rphicComponent | M0rphicZone | M0rphicStreamZone |
|---|---|---|---|
| Use Case | Render pre-built AI components | Layout orchestration with A/B testing | Real-time AI generation |
| Source | Dashboard Component Library | Pre-registered React components | AI generates on-demand |
| Data Binding | ✓ ${data.xxx} | ✗ Props only | ✗ Prompt context |