Can't save anything to storage
See original GitHub issueCurrent behavior
I get an error when trying to save anything but a string.
Expected behavior
To be able to save objects.
Repro steps
I tried saving the object from the docs:
const legacyStorage = new LegacyStorage()
type StorageModel = {
user: {
name: string
age: number
}
}
const storage = AsyncStorageFactory.create<StorageModel>(legacyStorage)
async function saveItem() {
const myUser = {
name: 'John',
age: 22
};
await storage.set('user', myUser);
}
// Somewhere else...
saveItem()
Environment
- Async Storage version: ^2.0.0-rc.2
- React-Native version: 0.61.5
- Platform tested: iOS
- Logs/Error that are relevant:
WARN [AsyncStorageLegacy] The value for key "user" is not a string. This can lead to unexpected behavior/errors. Consider stringifying it.
Passed value: [object Object]
Passed key: user
If I change StorageModel
to
type StorageModel = {
user: string
}
and stringify the object before saving, it works (and I can also read it back, as a string, of course). But that’s not really what I’d expect 😞
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Why am I unable to save a file on my computer?
Insufficient disk space ... If the location you are saving the file does not have sufficient disk space to store the file, the...
Read more >Can't save any files on any folder after latest windows update
If I try to save something it says "C:\Users\User\Documents\note.txt File not found. ... I have enough disk space to store the file.
Read more >[Fixed] Can't Save Files to USB Flash Drive - EaseUS
Here, three practical methods are available to help when you can't save files to a USB flash drive, or the flash drive not...
Read more >6 Common Reasons & Solutions When Files Cannot Be ...
6 Common Reasons & Solutions When Files Cannot Be Saved to USB Flash Drive · 1. No Permission · 2. Write Protection ·...
Read more >Open, save, or delete files - Chromebook Help - Google Support
Your Chromebook's hard drive has limited space, so your Chromebook will sometimes delete downloaded files to free up space. Learn how to store...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, understood 👍🏻
Thanks for all the explanations!
Thanks for the quick reply!
Sadly, I don’t have too much JS experience to acknowledge all the implications of serialization and/or have any suggestions; I’d probably stringify it.
What about using an SQLite database, like on Android? If it’s possible there, should be possible here as well, since iOS supports it as well?
If it’s truly no way to do it, I suppose so, because that piece of code definitely looks like it should save 🙃