Plain Components

Events

Simple Interactive WebAssembly

Components that can't derive from RfEventComponent (third-party or legacy components) can still read hub state through an ordinary [CascadingParameter].

How it works

Try it: change each theme. The two cards don't affect each other.

  • PlainThemedCard is a plain ComponentBase with [CascadingParameter] ThemeState? Theme. It knows nothing about the hub.
  • In the first card, options.CascadeRootState<ThemeState>() (see EventsDemoHub.Configure) exposes the root theme as a CascadingValueSource<ThemeState>.
  • In the second card, <StateScope TState="ThemeState" CascadeValue="true"> provides a separate instance to its subtree and also cascades it.
  • ThemePicker resolves the nearest provider, so the same component writes the root theme in the first card and the scoped theme in the second.
  • Trade-off: cascade consumers re-render on every change. Event-aware consumers can use selectors (ThemePicker only watches Name).

Root theme CascadeRootState<ThemeState>()

renders: 1
Plain component reading the root theme
Theme: Light
renders: 1

Scoped theme <StateScope CascadeValue="true">

renders: 1
Plain component inside the StateScope
Theme: Ocean
renders: 1
An unhandled error has occurred. Reload 🗙