-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for async storages (e.g. AsyncStorage for React Native) #14
Comments
Hey @jgornick, thanks for the suggestion. Off the top of my head, yes, I think that would be all. |
Expect a PR soon 😄 |
Started to work on the change here: https://github.com/jgornick/react-storage-hooks/blob/14-add-async-storage-support/src/common.ts Any feedback or help would be greatly appreciated 😄 |
Looking good at a quick glance! Feel free to open a PR if you want and I'll take a closer look, but please make sure to add some test cases to cover the new async behavior. Thanks! |
@soyguijarro Looking at this a bit more, this is a bit more difficult than I originally thought. A couple of concerns:
Again, I must admit, I'm not a hooks expert. However, the more I dig into this, the more it seems like a breaking change more than anything. If I'm not far off on this, as the owner of the library, are you OK with breaking API changes? Do we split out async support into their own hooks? Thoughts? |
Just as an update, I did start to look at ways to implement The change to the behavior of the hook then is that the I also started to modify the tests for the hook as well: https://github.com/jgornick/react-storage-hooks/blob/14-add-async-storage-support/src/tests/state.test.ts#L16-L27. They use the Any feedback would be greatly appreciated! |
You're totally right @jgornick, this would be a breaking change, but I'm fine with that. I think having async support would solve this SSR issue as well, so it's probably worth doing. Having sync and async versions of the hooks might look like it simplifies the sync use case, but it introduces complexity for users anyway: you now need to choose between the two hook flavors which have slightly different APIs, switch between them if you change your storage... Not worth it IMHO. I'd go with converting everything to async. For consumers using sync storages like |
@soyguijarro I'm not quite sure I know exactly what I'm doing, but I've made a commit that shows the updated interface for the state hook. I've also started to make some changes to the reducer hook, but not finished. Any chance you can have a look so far with what's there and if I should continue with updating tests? Thanks! |
Let's move the conversation into #20 . |
Taking a quick look at the code, it doesn't seem like there's support for
await
ing ongetItem
,setItem
orremoveItem
from the storage instance.Would a change like this be as simple as converting the methods to support
async/await
?Do you see any other challenges with making the change?
The text was updated successfully, but these errors were encountered: