-
Notifications
You must be signed in to change notification settings - Fork 472
Create useAsyncStorage
hook
#16
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
Comments
It would probably have to return an object, since there are 4 possible operations on a single key. const { getItem, setItem, removeItem, mergeItem } = useAsyncStorage('@NameOfTheStore') |
Hmm, just realised I didn't read your suggestion properly @michalchudziak - my implementation is for storing and retrieving a single value so the benefit of using the hook would be that you don't need to always pass in the key. Whereas in your suggestion, the API would be identical to the existing one, so it doesn't provide any benefit that I can see. |
🎉 This issue has been resolved in version 1.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@michalchudziak I think this would accomplish what you were originally looking to do https://gist.github.com/msukmanowsky/08a3650223dda8b102d2c9fe94ad5c12 |
@msukmanowsky Kinda... That implementation only detects changes from within the same component's instance. |
Oh, yes! Nice! Imma do that :) |
@msukmanowsky It is great implementation of the useAsyncStorage custom hook. Works perfectly! However, lauchPackager.command gives me a warning: RCTBridge required dispatch_sync to load RCTDevLoadingView. This may lead to deadlocks. Do you have any idea why it happens? |
@michalchudziak I have updated and fixed to ensure the code is efficient, the code you shared above will return an infinite loop even on |
What do you think of creating
useAsyncStore
hook, that encapsulates the most popular AsyncStorage methods?Where
setItem(key, value)
would save the key in@NameOfTheStore:${key}
, andgetItem(key)
would read from it.It's just a thought 😅
The text was updated successfully, but these errors were encountered: