Use Render
Gives components of your own the same Render parameter as the primitives.
Text component rendered as a paragraph tag
Text component rendered as a strong tagUseRender builds a part of your own: it renders DefaultTagName, or
your own element through Render, with your attributes. Its State becomes data attributes:
true renders data-name, other values data-name="value", and
false and null nothing.
Anatomy
@using Blazix.Primitives
<UseRender DefaultTagName="p" State="@state">
<Render Context="text">
<strong @attributes="text.Attributes">...</strong>
</Render>
</UseRender>Parts of your own
For a part with state of its own, derive from PrimitivePart<TRenderProps>, as the primitives do.
Add the part's attributes in BuildAttributes with an
AttributeBuilder, and describe its state for
Render in CreateRenderProps:
public sealed record BadgeRenderProps(IReadOnlyDictionary<string, object> Attributes, bool Active)
: RenderProps(Attributes);
public class Badge : PrimitivePart<BadgeRenderProps>
{
[Parameter] public bool Active { get; set; }
protected override string Tag => "span";
protected override void BuildAttributes(AttributeBuilder attributes) =>
attributes.Flag("data-active", Active);
protected override BadgeRenderProps CreateRenderProps(IReadOnlyDictionary<string, object> attributes) =>
new(attributes, Active);
}API Reference
UseRender
Renders a <div> element.
Other attributes are passed to the element it renders.