Support for asynchronous Storage (React Native)
BenJeau opened this issue · 2 comments
BenJeau commented
Using this package does not work with React Native since their Storage API (aka the AsyncStorage
API, here's a link to their docs) is asynchronous and this package does not seem to support an asynchronous Storage API. This issue is to simply open the conversation this subject.
The following is what I used to set the storage:
const {persistAtom} = recoilPersist({
storage: AsyncStorage,
});
The error message:
There's an error here since toParse
is a Promise.
Looking at the code, you could check if getItem()
or/and setItem()
is a promise to know if its async or not, then transform the functions to be async. This is potentially a naïve idea, but I'm not sure how it could be implemented otherwise, maybe you have a better idea on its implementation.