Building a component with RenderTree
Building components can be done using just a .razor
file, which is the recommended approach most of the time, but it’s good to learn how to also build them using RenderTree
, to learn how things work under the hood. This will help you build better components with Razor. For example, with RenderTree
you can control how Blazor determines the changes to render in the UI, which can improve performance in some special cases. We will see an example of this in the Controlling the rendering using the @key directive section.
It’s rare to encounter a scenario where you’re required to use the RenderTree
method, and it’s also not recommended, as building complex components is extremely hard with RenderTree
compared to .
razor
files.
To keep things simple, we will build the same little UI with the <h1>
tag and <button>
and configure it to update its content when we click on the button as we did in the Updating the...