CascadedParameter: When is its value applied to my components property

670 views Asked by At

I've got a very simple szenario. I put a AppState component all over my blazor application (outer component in app.razor).

Now I want to cascade down a Property value to all my nested components within my application. This works in the most cases quite good, but on some Components there are some operations which try to access my cascaded values before they get applied to my class properties.

In my particular case I try to access a variable within my cascaded class in a property getter. But it returns me a null reference due, because the cascaded values has not been applied yet.

Can I control the sequence how the property values are applied or do i have to remove the code from the setter and rewrite the code doing this initalization somewhere later in the lifecylce

1

There are 1 answers

0
Douglas Riddle On BEST ANSWER

You should be able to handle this with a wrapper in the MainLayout.razor file so that site content does not attempt to render until the cascading value has been loaded.

@if(CascadedValueNull)
{
    <div>Loading...</div>
}
else
{
    <CascadingValue Value="@SomeValue">
        @Body
    </CascadingValue>
}