Skip to content

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 render composition 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 a data-* attribute on the element and the second argument of a render callback, so callers style the state with data-attribute variants rather than reading it in React.
  • Type the props with useRender.ComponentProps: it adds the render prop to the element's own props.
  • Merge the part's own props with mergeProps: the props parameter is spread on the element and merged with the render element's props.

Parameters and composition types

tsx

useRender.Parameters, useRender.ReturnValue and useRender.ComponentProps are namespace aliases of UseRenderParameters, UseRenderReturnValue and UseRenderComponentProps.

Examples

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.

Parameters
ParameterTypeDescription
params requireduseRender.Parameters<State, RenderedElementType, Enabled>No description

Returns

UseRenderReturnValue<Enabled>