author-component

仓库创建 2026年2月4日最近提交 18 小时前SkillHot 收录 20 天前
▸ 精选理由

强调参数流动与事件回流等最佳实践,利于构建可维护组件库。

这个 Skill 做什么

编写或审查 Blazor .razor 组件的结构、参数与生命周期模式规范。

帮你设计或审查 .razor 组件的结构、参数和生命周期用法,覆盖 [Parameter]、EventCallback、RenderFragment、OnInitializedAsync、OnParametersSet、IAsyncDisposable、CancellationToken 等常见模式。适用于纯 Blazor 组件开发(不含 JS 互操作或浏览器 API)的代码编写或规范校验。强调数据下行、事件上行、不在参数上直接变更,以及异步生命周期与 CSS 隔离等最佳实践,降低组件出错概率。

▸ 展开 SKILL.md 英文原文

Create or review Blazor components (.razor files) with correct architecture. USE FOR: writing new Blazor components that do NOT involve JavaScript interop, implementing parameters and EventCallback, RenderFragment slots, component lifecycle (OnInitializedAsync, OnParametersSet), async patterns, IAsyncDisposable, CancellationToken, CSS isolation, code-behind. DO NOT USE FOR: creating new projects (use create-blazor-project), JavaScript interop or calling browser APIs from Blazor (use use-js-interop), forms and validation (use collect-user-input), prerendering issues (use support-prerendering), HTTP data fetching patterns (use fetch-and-send-data), coordinating state between unrelated components (use coordinate-components).

开发编程Blazor组件生命周期通用
4.8k
Stars
351
Forks
40
仓库内 Skill
+610
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/dotnet/skills/main/plugins/dotnet-blazor/skills/author-component/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/dotnet/skills/main/plugins/dotnet-blazor/skills/author-component/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# Author Blazor Component

## Core Rules

- Data flows **down** via `[Parameter]`. Events flow **up** via `EventCallback<T>` (never `Action`/`Func`).
- Never mutate `[Parameter]` properties. Copy to a private field in `OnParametersSet`.
- Use `[Parameter] public T Prop { get; set; }` — never `required` or `init` (causes BL0007).
- Use `[EditorRequired]` for required parameters.
- Handle all states: loading, empty, loaded, error — each with `@if`/`@else`.
- Use `@key` on repeated elements in loops for efficient diffing.
- Use `IReadOnlyList<T>` (not `IEnumerable<T>`) for collection parameters.

## RenderFragment & Generics

```csharp
[Parameter] public RenderFragment? ChildContent { get; set;
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有