Looks like the syntax for preserving state between prerendering and rendering on the client has changed in RC 1.
Specifically ComponentApplicationState is now called PersistentComponentState and the usage has changed slightly.
It now seems you need to grab the result of ApplicationState.RegisterOnPersisting() and store that as a field which you can then call .Dispose() on when disposing of your component.
@code {
private ProductListModel _model;
private PersistingComponentStateSubscription _subscription;
protected override async Task OnInitializedAsync()
{
_subscription = ApplicationState.RegisterOnPersisting(PersistModel);
if (ApplicationState.TryTakeFromJson("model", out ProductListModel model))
_model = model;
else
_model = await _api.ProductList(new ProductListQuery());
}
private Task PersistModel()
{
ApplicationState.PersistAsJson("model", _model);
return Task.CompletedTask;
}
public void Dispose()
{
_subscription.Dispose();
}
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Looks like the syntax for preserving state between prerendering and rendering on the client has changed in RC 1.
Specifically
ComponentApplicationStateis now calledPersistentComponentStateand the usage has changed slightly.It now seems you need to grab the result of
ApplicationState.RegisterOnPersisting()and store that as a field which you can then call.Dispose()on when disposing of your component.Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.