-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to retain state of a revisited page? #145
Comments
Yes, a simple AppState pattern can be used if you want to load the data for a page from in memory. public class AppState
{
public string? MyProperty { get; set; }
} Then yes, register it as a singleton: // Program.cs
appBuilder.Services.AddSingleton<AppState>(); Then it can be injected into a page: @* MyPage.razor *@
@inject AppState AppState And used like so: @code {
private string? _myProperty;
protected override void OnInitialized()
{
_myProperty = AppState.MyProperty;
}
} Be aware of the gotcha that if you bind any UI elements to properties on AppState, updating any values in AppState from a different view will not cause a re-render of the current view - you will need to manually trigger it yourself somehow. |
seem no better way |
thanks, I watched your YouTube video, great sharing. |
I want to retain the sate of the page, is there a good way?
using a singleton class to hold the sate and inject to the page?
The text was updated successfully, but these errors were encountered: