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
-
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