Langsung ke konten
Skillpedia
Website & UI (frontend)5.8k Β· #14561

author-component

Fungsinya

Skill ini memandu penulisan dan peninjauan komponen Blazor, yaitu bagian antarmuka web yang bisa dipakai ulang. Skill ini untuk pengembang .NET yang membangun atau memperbaiki komponen UI Blazor.

Kapan dipakai

  • βœ“Saat Anda menulis komponen Blazor baru yang memiliki parameter atau event.
  • βœ“Saat Anda perlu meninjau komponen untuk kesalahan lifecycle atau async.
  • βœ“Saat sebuah komponen perlu pembersihan untuk timer, langganan, atau pembatalan.

Link skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-blazor/skills/author-component/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/dotnet/skills/blob/main/plugins/dotnet-blazor/skills/author-component/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œTulis komponen kartu produk Blazor yang menerima parameter produk dan memunculkan event saat ditambahkan ke keranjang.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent memakai aliran data ke bawah melalui parameter dan event ke atas, mengikuti aturan lifecycle, menangani status memuat dan galat, serta membersihkan sumber daya.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

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

[Parameter] public RenderFragment? ChildContent { get; set; }
[Parameter] public RenderFragment<TItem>? RowTemplate { get; set; }  // generic template

Use @typeparam TItem for generic components.

File Patterns

  • Single-file: .razor with @code block when logic < ~50 lines.
  • Code-behind: .razor + .razor.cs with partial class when logic > ~50 lines.

Disposal

Implement IAsyncDisposable (not IDisposable) when the component owns subscriptions, timers, or CTS. In DisposeAsync: unsubscribe (-=), cancel CTS, dispose resources. Never call StateHasChanged.

Async Patterns

  • await every async operation. Never use .Result, .Wait(), Task.Run, ContinueWith, Thread.Start.
  • Debounce: Task.Delay + CancellationTokenSource. Cancel old CTS, create new, await delay, do work. Never use System.Threading.Timer or System.Timers.Timer.
  • Polling: Loop in OnInitializedAsync with await Task.Delay(interval, token) β€” stays on sync context.
  • External events (Action<T>): Use async void handler + await InvokeAsync(() => { state++; StateHasChanged(); }) + catch β†’ DispatchExceptionAsync. Never _ = InvokeAsync(...).
  • Cancel CTS in DisposeAsync. Don't catch ObjectDisposedException β€” use CTS cancellation.

Don'ts

  • required/init on [Parameter] β€” runtime failure
  • Mutate [Parameter] β€” copy to private field in OnParametersSet
  • Action/Func for events β€” use EventCallback<T>
  • Task.Run/.Result/.Wait()/Timer for debounce β€” deadlock or thread-pool escape
  • Inline style attributes β€” use CSS classes or data-* attributes
  • catch { throw; } β€” use when guard or let exceptions propagate
  • Gold-plating: ARIA, wrapper divs, accessibility features not requested
  • _ = InvokeAsync(...) β€” swallows exceptions; use async void + DispatchExceptionAsync
Pertanyaan umum

Apakah mencakup JavaScript interop?

Tidak. Komponen yang memerlukan JavaScript ditangani skill terpisah.

Apakah menangani gaya?

Skill mencakup CSS isolation untuk gaya komponen.

Apakah mencakup proyek baru?

Tidak. Skill ini untuk menulis komponen, bukan membuat seluruh proyek.

Detail

Deskripsi asli dari pembuat

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),

repo: dotnet/skills

Popularitas

Bintang GitHub
5.8k
Peringkat
#14561
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa