What do you think of creating useAsyncStore hook, that encapsulates the most popular AsyncStorage methods?
const [getItem, setItem] = useAsyncStorage('@NameOfTheStore')
Where setItem(key, value) would save the key in @NameOfTheStore:${key}, and getItem(key) would read from it.
It's just a thought 馃槄
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.
:tada: This issue has been resolved in version 1.1.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
@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.
@TheDSCPL true, but that's usually handled by just using this at a top-level App.js and supplying the value to subcomponents via something like Context.
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?
Most helpful comment
@michalchudziak I think this would accomplish what you were originally looking to do https://gist.github.com/msukmanowsky/08a3650223dda8b102d2c9fe94ad5c12