Using RenderFragment
To make our components even more reusable, we can supply them with a piece of Razor syntax. In Blazor, you can specify RenderFragment
, which is a fragment of Razor syntax that you can execute and show.
Now that we have added actions and used EventCallback
to communicate changes, we will see how we can execute RenderFragment
in the next section.
There are two types of render elements, RenderFragment
and RenderFragment <T>
. RenderFragment
is simply a Razor fragment without any input parameters, and RenderFragment <T>
has an input parameter that you can use inside the Razor fragment code by using the context
keyword. We won't go into depth about how to use this now, but later in this chapter, we will talk about a component (Virtualize
) that uses RenderFragment<T>
and, in the next chapter, Chapter 6, Building Forms with Validation, we will implement a component using RenderFragments<T>
.
We can make RenderFragment the default content...