I'm using the Blazor Tabs component, where each tab contains a custom component, some of which are quite expensive to load.
I wish the state of the custom components to be retained when flicking between tabs, so I have used "client" mode. However, I would also like to load the required tab data in a lazy mode, so that the data is loaded only when the given tab is first selected.
I think what I need is to pass a parameter down to the custom component e.g. IsSelected, and postpone loading the data until this parameter is set to true. However I have tried something along these lines, and the custom component is not being informed when the parameter changes
Thanks for the response. Yes I am able to see/confirm that the two-way binding works as expected. The issue I have experienced with server RenderMode is that the components within the tab items are destroyed/re-created when flipping between tabs, yet for my use case all of the state (including positioning of DataGrid etc within the tab) needs to be preserved.
Is there a way of getting notified when a tab is (first) selected, together with retaining state within all of the tabs?
I have got it working by triggering StateHasChanged() asynchronously, i.e. after the tab selection event has completed. I'm not sure this would be considered robust or good practice, but it appears to have the desired effect of allowing lazy loading and retaining all state within the tabs.
int selectedIndex = 0;
public int SelectedIndex
{
get
{
return selectedIndex;
}
set
{
selectedIndex = value;
Task.Run(() => InvokeAsync(StateHasChanged));
}
}