This repository was archived by the owner on Dec 26, 2025. It is now read-only.
Replies: 2 comments
-
|
Hi @adamsd5, I'm always happy to improve the samples. Do you have any ideas about specific examples we could use? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
The way I always do it is as such: Assuming we want to retrieve a Settings object (but could be anything) if (await _localStorage.ContainKeyAsync("Settings") == false)
{
return new Settings(); // Init this however you like
}
return await _localStorage.GetItemAsync<Settings>("Settings"); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new. The usage example is not a typical use case. I can't think of any reason you would write a thing to local storage and then immediately read it. A better example is to show how to check if a value is stored locally first and use it if it does. And if it doesn't, initialize it. How do I do that? Even better, how would I make a property that persists to local storage? What does that code look like?
(The example I'm referring to:
await localStorage.SetItemAsync("name", "John Smith");
var name = await localStorage.GetItemAsync("name");
)
Beta Was this translation helpful? Give feedback.
All reactions