useRender
Builds a part that supports the render prop and state data attributes.
useRender renders an element that callers can replace or compose through a render prop, the same way Base UI parts work. It is Base UI's useRender re-exported through a Dify UI subpath.
tsx
Usage guidelines
- Use it for a Dify-authored part with no Base UI counterpart: a part that renders a plain element, such as a link or a card entry, gets the same
rendercomposition as the rest of the library. - Do not wrap a Base UI part with it: Base UI parts already accept
render. Wrap the part directly and forward its props. - Do not rebuild an existing component: when a Dify UI component already covers the element, compose it instead of building a look-alike with
useRender. - Expose state through
state: each state property becomes adata-*attribute on the element and the second argument of arendercallback, so callers style the state with data-attribute variants rather than reading it in React. - Type the props with
useRender.ComponentProps: it adds therenderprop to the element's own props. - Merge the part's own props with
mergeProps: thepropsparameter is spread on the element and merged with therenderelement's props.
Parameters and composition types
tsx
useRender.Parameters, useRender.ReturnValue and useRender.ComponentProps are namespace aliases of UseRenderParameters, UseRenderReturnValue and UseRenderComponentProps.
Examples
Link part with state
The external state becomes a data-external attribute, and a caller can swap the anchor for a router link through render.
tsx
API reference
useRender
Renders a Base UI element.
| Parameter | Type | Description |
|---|---|---|
params required | useRender.Parameters<State, RenderedElementType, Enabled> | No description |
Returns
UseRenderReturnValue<Enabled>