Root-level cascading values
Root-level cascading values are a new feature in .NET 8. This is a great way to share state not only between components but also between different render modes. It will automatically add a cascading value; we have already used this feature, and then we added AddCascadingAuthenticationState()
, which uses the root-level cascading value in the background.
This does not share the value between InteractiveServer and InteractiveWebAssembly, though, but gives us a way to share the state between components without using dependency injection.
The really nice thing is that if the value changes, it will automatically change the parameter and trigger a rerender of the component. No special code is needed inside the component. But subscribing to value changes does have a cost, so be careful with how many things you use with root-level cascading values.
Usage could look something like this:
@(Preferences?.DarkTheme)
@code {
[CascadingParameter(Name...