Define captures a component subtree as a named template. Use references it by name, optionally injecting scoped data. The template is defined once and can appear any number of times in the tree with different data.
Basic Usage
Use become interpolation values scoped to that instance of the template.
Define
Define uses the context manager like any container, but it does not attach itself to a parent — it lives outside the component tree. Pass it to UIResponse via the defs parameter.
Use
Use references a Define by name. Any kwargs that aren’t base component fields (css_class) become scoped interpolation values for the template.
With ForEach
Inside a ForEach, each item’s fields become the interpolation context automatically — soUse doesn’t need explicit overrides:
API Reference
Define Parameters
Template name, referenced by
Use. Can be passed as a positional argument.Use Parameters
The template name to reference (must match a
Define name). Can be passed as a positional argument.Scoped interpolation values. Any kwarg that isn’t
css_class becomes a scoped state override for the template.Additional Tailwind CSS classes.
Protocol Reference
Define serializes to the template body in the defs envelope:
defs
Use without overrides serializes to a $ref node:
Use (bare)
Use wraps the ref in a State node:
Use (with overrides)