blazor▌
mindrally/skills · updated Apr 8, 2026
You are an expert in Blazor development with deep knowledge of both Blazor Server and Blazor WebAssembly.
Blazor Development Guidelines
You are an expert in Blazor development with deep knowledge of both Blazor Server and Blazor WebAssembly.
Component Architecture
Component Design
- Create small, focused components
- Use component parameters for input
- Use EventCallback for output/events
- Implement IDisposable for cleanup
- Use cascading parameters sparingly
Component Structure
@page "/users/{Id:int}"
@inject IUserService UserService
<h1>@User?.Name</h1>
@code {
[Parameter]
public int Id { get; set; }
private User? User { get; set; }
protected override async Task OnInitializedAsync()
{
User = await UserService.GetUserAsync(Id);
}
}
Component Lifecycle
Lifecycle Methods
OnInitialized/OnInitializedAsync: Initial setupOnParametersSet/OnParametersSetAsync: When parameters changeOnAfterRender/OnAfterRenderAsync: After DOM updatesDispose: Cleanup resources
Best Practices
- Use
OnInitializedAsyncfor data loading - Check
firstRenderinOnAfterRenderAsync - Dispose subscriptions and timers
- Avoid long-running synchronous code
Data Binding
One-Way Binding
<p>@message</p>
<input value="@inputValue" />
Two-Way Binding
<input @bind="inputValue" />
<input @bind="inputValue" @bind:event="oninput" />
Event Handling
<button @onclick="HandleClick">Click</button>
<button @onclick="() => HandleClickWithParam(id)">Click</button>
<button @onclick="HandleClickAsync">Async Click</button>
Render Optimization
Prevent Unnecessary Renders
- Use
@keyfor list items - Implement
ShouldRender()when appropriate - Use
StateHasChanged()judiciously - Avoid inline handlers in loops
Virtualization
<Virtualize Items="@items" Context="item">
<ItemContent>
<div>@item.Name</div>
</ItemContent>
</Virtualize>
State Management
Component State
- Use private fields for component state
- Call
StateHasChanged()when state changes externally - Use
InvokeAsyncfor thread-safe updates
Cascading Parameters
<CascadingValue Value="@currentTheme">
<ChildComponent />
</CascadingValue>
<!-- In child component -->
[CascadingParameter]
public Theme CurrentTheme { get; set; }
State Containers
- Create injectable state services
- Use events for state change notifications
- Consider Fluxor for complex state management
Blazor Server vs WebAssembly
Blazor Server
- State lives on server
- Real-time connection via SignalR
- Faster initial load
- Requires stable connection
- Better for internal apps
Blazor WebAssembly
- Runs entirely in browser
- Larger initial download
- Works offline (PWA capable)
- No server resources per user
- Better for public apps
API Integration
HTTP Client
@inject HttpClient Http
private async Task LoadData()
{
users = await Http.GetFromJsonAsync<List<User>>("api/users");
}
Error Handling
try
{
users = await Http.GetFromJsonAsync<List<User>>("api/users");
}
catch (HttpRequestException ex)
{
errorMessage = "Failed to load users";
}
Error Handling
Error Boundaries
<ErrorBoundary>
<ChildContent>
<RiskyComponent />
</ChildContent>
<ErrorContent Context="ex">
<p>An error occurred: @ex.Message</p>
</ErrorContent>
</ErrorBoundary>
Global Error Handling
- Implement
IErrorBoundaryfor custom handling - Log errors to server
- Show user-friendly messages
Testing
bUnit Testing
[Fact]
public void ComponentRendersCorrectly()
{
using var ctx = new TestContext();
var cut = ctx.RenderComponent<Counter>();
cut.Find("p").MarkupMatches("<p>Current count: 0</p>");
cut.Find("button").Click();
cut.Find("p").MarkupMatches("<p>Current count: 1</p>");
}
Authentication
Setup
- Use
AuthenticationStateProvider - Use
AuthorizeViewfor conditional UI - Use
[Authorize]attribute on pages - Implement custom auth state provider for JWT
AuthorizeView
<AuthorizeView>
<Authorized>
<p>Welcome, @context.User.Identity?.Name!</p>
</Authorized>
<NotAuthorized>
<p>Please log in.</p>
</NotAuthorized>
</AuthorizeView>
Performance Tips
- Use
@keyfor dynamic lists - Implement virtualization for large lists
- Lazy load components with
@if - Minimize JavaScript interop calls
- Use streaming rendering in .NET 8+
Ratings
4.5★★★★★56 reviews- ★★★★★Aanya Malhotra· Dec 28, 2024
Solid pick for teams standardizing on skills: blazor is focused, and the summary matches what you get after install.
- ★★★★★Kofi White· Dec 16, 2024
blazor reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Kaira Agarwal· Dec 12, 2024
Keeps context tight: blazor is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Liam Liu· Dec 4, 2024
blazor has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Kaira Bansal· Dec 4, 2024
Registry listing for blazor matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Kofi Huang· Nov 23, 2024
Useful defaults in blazor — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Chinedu Kim· Nov 23, 2024
blazor reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Kabir Desai· Nov 11, 2024
We added blazor from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Kofi Kim· Nov 7, 2024
Registry listing for blazor matched our evaluation — installs cleanly and behaves as described in the markdown.
- ★★★★★Ama Rahman· Nov 3, 2024
blazor is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
showing 1-10 of 56