question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't save anything to storage

See original GitHub issue

Current 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rolandlethcommented, Feb 17, 2020

OK, understood 👍🏻

Thanks for all the explanations!

1reaction
rolandlethcommented, Feb 14, 2020

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?

Perhaps we can set expectations with better documentation?

If it’s truly no way to do it, I suppose so, because that piece of code definitely looks like it should save 🙃

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found