What are templated components in Blazor?

Category: C SharpWhat are templated components in Blazor?
Editor">Editor Staff asked 2 years ago

What are templated components in Blazor?

1 Answers
Editor">Editor Staff answered 2 years ago

Blazor uses the Razor template engine that generates HTML and serves to the web browsers. We can mix HTML and C# syntax in the Razor templates and Razor engine then compiles the Razor templates to generate the HTML.
 
Blazor (version 0.6.0) supports the templated component. It is a component that accepts one or more UI templates as parameters and these parameters can be used for component rendering. It allows us to write high-level reusable components. Using templated components, we can write a generic and more reusable component.
 
We can create the templated component by using one or more component parameters of type RenderFragment or RenderFragment<T>. The RenderFragment is a part of UI which is rendered by the component. It may have parameters that are used during the rendering of the component or while the RenderFragment is invoked.