You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.3KB

Skill 13 - Blazor Components

Core Concepts

  • Blazor apps are built from components.
  • Components combine markup, C# code, parameters, events, lifecycle methods, and rendering behavior.
  • Rendering can happen server-side, client-side, or with static server-side rendering depending on hosting model.

Component Rules

  • Keep components small and focused.
  • Use parameters for input and event callbacks for output.
  • Avoid putting complex business logic directly in components.
  • Extract reusable UI into child components.
  • Use services for data access and state that crosses components.
  • Be explicit about render modes and interactivity.

Lifecycle Rules

  • Use initialization lifecycle methods for loading setup data.
  • Use parameter-set lifecycle methods when behavior depends on changing parameters.
  • Avoid unnecessary calls to StateHasChanged.
  • Dispose subscriptions and unmanaged resources.

Forms

  • Use EditForm for model binding and validation.
  • Use validation attributes or custom validators for input rules.
  • Keep validation rules shared with the domain when practical.
  • Do not trust client-side validation alone.

Performance

  • Avoid excessive component re-rendering.
  • Use @key when rendering lists whose identity matters.
  • Keep large data operations out of the render path.

Powered by TurnKey Linux.