0
votes

When i learn about components in Reactjs, I can try something like this

<Component {...properties} /> Now, I learn Blazor. How can I pass properties to some component??

2

2 Answers

1
votes

You use [Parameter] within the component definition. For example, if you have a Blazor component like this

// BlazorComponent.razor
<div class="@Class">
  @ChildContent
</div>

@code {
  [Parameter] public string Class { get; set; }
  [Parameter] public RenderFragment ChildContent { get; set;}
}

You can consume that like this

<BlazorComponent Class="some-class">
  <p>Some Content</p>
</BlazorComponent>

Which will generate html like

<div class="some-class">
  <p>Some Content</p>
</div>