ContentResolver
import { ContentResolver } from 'cx/widgets'; Copied ContentResolver dynamically resolves content at runtime based on data. Use it when the content to display is unknown at build time, depends on data values, or needs to be lazy loaded.
<div className="flex items-center gap-4">
<LookupField value={m.fieldType} options={fieldTypes} label="Field Type" />
<ContentResolver
params={m.fieldType}
onResolve={(type) => {
switch (type) {
case "textfield":
return <TextField value={m.text} />
case "datefield":
return <DateField value={m.date} />
case "checkbox":
return <Checkbox value={m.checked}>Checked</Checkbox>
case "switch":
return <Switch value={m.checked} />
default:
return null
}
}}
/>
</div> How It Works
- The
paramsprop binds to a value in the store - When
paramschanges,onResolveis called with the new value onResolvereturns the widget configuration to render- For async loading,
onResolvecan return a Promise - Children are displayed as default content while loading
Structured Params
The params prop can be a structured object with multiple bindings:
<ContentResolver
params={{
type: m.fieldType,
required: m.isRequired,
}}
onResolve={({ type, required }) => {
// resolve based on multiple parameters
}}
/>
When any of the bound values change, onResolve is called with the updated object.
Configuration
| Property | Type | Description |
|---|---|---|
params | any | Parameter binding. Can be a single value or structured object. Content is recreated when params change. |
onResolve | function | Callback taking params and returning widget configuration or a Promise. |
mode | string | How resolved content combines with children: replace, prepend, or append. Default is replace. |
loading | boolean | Writable binding set to true while a Promise is resolving. |
children | any | Default content displayed while onResolve Promise is loading. |