How do you create a generic template component?

Templated components are often generically typed. To define a generic component, use the @typeparam directive to specify type parameters Generic template component When using generically typed components, the type parameter is inferred if possible. Otherwise, the type parameter must be explicitly specified using an attribute that matches the name of the type parameter. In the following example, TItem=” WeatherForecast “specifies the type. Reference: https://docs.microsoft.com/en-us/aspnet/core/blazor/templated-components?view=aspnetcore-3.1

How do you create a template component in Blazor?

Blazor supports templated components. These are components that accept one or more UI templates as parameters and these parameters can be used for component rendering. A templated component can be created by using one or more component parameters of type RenderFragment or RenderFragment<T>. The RenderFragment is a part of the UI that is rendered by the component. It may have parameters that are used during the rendering of the component or while the RenderFragment is invoked. Table template component When using a templated component, the template parameters can be specified using child elements that match the names of the parameters (TableHeader and RowTemplate in the following example).

How do you handle events in Blazor?

In Blazor developers can handle any event by using the on<eventname> attribute with an HTML element. The attribute’s value is treated as an event handler. Blazor provides a set of event argument types that map to events. Following is a list of event types and the event argument type they map to: Focus events: FocusEventArgs Mouse events: MouseEventArgs Drag events: DragEventArgs Keyboard events: KeyboardEventArgs Input events: ChangeEventArgs/EventArgs Clipboard events: ClipboardEventArgs/EventArgs Touch events: TouchEventArgs Pointer events: PointerEventArgs Media events: EventArgs Progress events: ProgressEventArgs In the example, the event keypress is handled by using lambda expression the event is triggered for every keypress in the input element. Reference link: https://visualstudiomagazine.com/articles/2018/10/01/blazor-event-handling.aspx

How do you build Blazor apps with SignalR?

Blazor Server In server code, configure SignalR in the Startup.cs class file as follows. And then create a SignalR hub class as follows. Blazor client Create a Blazor app and add the package Blazor.Extensions.SignalR to the client. Then write the code to connect the Hub and event handler as follows. OnInitializedAsync method, connect to the Web API. ReceiveMessage method, used in the SignalRHub class. ReceiveMessage method, concatenate the name and message parameters, and append them to a list. The StateHasChanged method will update the bindings in the HTML. The SendMessage method will invoke the Send method in the hub with name and message parameters. Reference link: https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr-blazor-webassembly?view=aspnetcore-3.1&tabs=visual-studio#add-the-signalr-client-library