/dotnet-blazor:blazor-js-interopfrom dotnet-blazor
Patterns for calling JavaScript from .NET Blazor and .NET methods from JavaScript using IJSRuntime, JSInvokable, and collocated JS modules. Includes disposal and lifecycle best practices.
Ships in dotnet-blazor. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
@inject IJSRuntime JS
@code {
private async Task ShowAlert()
{
await JS.InvokeVoidAsync("alert", "Hello from Blazor!");
}
private async Task<string> GetValue()
{
return await JS.InvokeAsync<string>("localStorage.getItem", "key");
}
// With element reference
private ElementReference _inputRef;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JS.InvokeVoidAsync("focusElement", _inputRef);
}
}
}
// Static .NET method
[JSInvokable]
public static Task<string> GetDataFromDotNet()
{
return Task.FromResult("Hello from .NET!");
}
// Instance method
private DotNetObjectReference<MyComponent>? _dotNetRef;
protected override void OnInitialized()
{
_dotNetRef = DotNetObjectReference.Create(this);
}
[JSInvokable]
public void HandleJsCallback(string data)
{
_message = data;
StateHasChanged();
}
public void Dispose() => _dotNetRef?.Dispose();
// Call static method
const result = await DotNet.invokeMethodAsync('MyApp', 'GetDataFromDotNet');
// Call instance method
dotNetRef.invokeMethodAsync('HandleJsCallback', 'data from JS');
Components/Pages/
├── Map.razor
├── Map.razor.cs
└── Map.razor.js ← Collocated JS module
// Map.razor.js
export function initializeMap(element, options) {
const map = new google.maps.Map(element, options);
return map;
}
export function dispose() {
// Cleanup
}
// Map.razor.cs
private IJSObjectReference? _module;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_module = await JS.InvokeAsync<IJSObjectReference>(
"import", "./Components/Pages/Map.razor.js");
await _module.InvokeVoidAsync("initializeMap", _mapElement, _options);
}
}
public async ValueTask DisposeAsync()
{
if (_module is not null)
{
await _module.InvokeVoidAsync("dispose");
await _module.DisposeAsync();
}
}
.razor.js modules over global scriptsIJSObjectReference and DotNetObjectReferenceOnAfterRenderAsync (DOM must exist)IJSRuntime in Server mode, IJSInProcessRuntime only in WASMJSDisconnectedException in Blazor Server for graceful cleanupWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
blazor, javascript-interop, dotnet, ijsruntime, js-invokable, collocated-js
19 skills in this plugin
/aspnet-core-apisASP.NET Core API development with minimal APIs, controllers, middleware, OpenAPI, and best practices/blazor-auth-securityAuthentication and authorization in Blazor with ASP.NET Core Identity, Entra ID, JWT, and policy-based auth/blazor-componentsBlazor component model including render modes, lifecycle, parameters, event handling, and component communication/blazor-forms-validationBlazor forms, EditForm, input components, DataAnnotations, FluentValidation, and custom validation/blazor-performanceBlazor rendering optimization, virtualization, lazy loading, caching, and memory management/blazor-testingTesting Blazor apps with bUnit, xUnit, WebApplicationFactory, and integration testing patternsnpx claudepluginhub thelobbi/claude --plugin dotnet-blazorOther plugins' skills for the same job