Blazor client side dynamic-component in mudblazor component not updating dom after type has been set with blazor-state

Viewed 349

I have this application which sourcecode can be found here github

enter image description here

When clicking on Example it loads the example page which in turn should load the right sidebar dynamically by calling blazor state actions in which the drawer component type (Sidebar) is set and the right sidebar is opened.

enter image description here

It runs through the code steps but the last one the oninitialized of the sidebar is never called eventhough it has been dynamically loaded into the component. A code snippet how I set it up is given below.


<MudDrawer Open="@DrawerEnd" Width="300px" ClipMode="DrawerClipMode.Never" Anchor="Anchor.End" Elevation="1" Variant="@DrawerVariant.Persistent">
    <MudDrawerHeader>
        <MudText Typo="Typo.h6">Settings</MudText>
    </MudDrawerHeader>
    @if (DrawerComponent is not null)
    {
        <DynamicComponent Type="@DrawerComponent" />
    }
</MudDrawer>

public partial class AppState
{
    public class LoadDrawerComponentHandler : ActionHandler<LoadDrawerComponentAction>
    {
        public AppState AppState => Store.GetState<AppState>();

        public LoadDrawerComponentHandler(IStore store) : base(store) { }

        public override async Task<Unit> Handle(LoadDrawerComponentAction action, CancellationToken aCancellationToken)
        {
            Console.WriteLine("loaddrawer:component:handler");
            AppState.DrawerComponent = action.Component;
            return await Unit.Task;
        }
    }
}

The sidebar oninitialized is only called when you click the Example link a second time which is weird behavior. Anyone know why? Any help is much appreciated.

enter image description here

enter image description here

0 Answers
Related