Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Shares state between non-parent-child Blazor components via cascading values, scoped services with change events, or CascadingValueSource.
86% 100%+14 ptsof test cases passed
Passed 22 of 22 test cases with the skill, and 19 of 22 without it.
I'm building a Blazor application and need to share active theme configurations across all pages and components, including interactive components nested inside static layouts. When users switch themes, all consuming components need to update immediately without forcing a browser refresh. Could you provide a complete C# and Razor code example demonstrating how to register this shared state globally in startup, trigger update notifications from a toggle component, and consume the state in child components?
Registers the theme state globally using AddCascadingValue with CascadingValueSource in Program.cs
3 of 3 safety checks passed
Read AGENTS.md at the workspace root to learn the project's conventions before making changes.
| Need | Mechanism | When to use |
|---|---|---|
| Subtree (same render mode) | CascadingValue component | Theme, layout config within a layout |
| App-wide (all render modes) | CascadingValueSource<T> via DI | Current user, feature flags, theme shared globally |
| Mutable shared state within a circuit | Scoped service + Action event | Shopping cart, notification count, selected filters |
For parent→child one level: use [Parameter] / EventCallback (see author-component skill).
For persisting state across prerender→interactive: see support-prerendering skill.
CascadingValueSource<T> (Step 4)Program.cs with AddCascadingValue(...) and isFixed: false[CascadingParameter] in child componentsNotifyChangedAsync(newValue) — never page reloadStateHasChanged from background threads in InvokeAsyncIDisposable — dispose timers, cancel tokens, unsubscribe eventsWrap a subtree with <CascadingValue> to flow data to all descendants without passing it through every intermediate component.
@* In a layout or parent component *@
<CascadingValue Value="theme">
@Body
</CascadingValue>
@code {
private ThemeInfo theme = new() { ButtonClass = "btn-primary" };
Next to this one in the catalogue, plus more from the same author.