react-native-mmkv-storage
react-native-mmkv-storage copied to clipboard
v0.9.0 - What can we add/change or enhance?
I have some ideas on how we can make the library even better.
v0.7.0 (Released)
- [x] Migrate to typescript
- [x] Optionally persist default values in hooks
- [x] Add a way to mock the library with Jest
- [x] Add tests for mocked storage
- [x] Expo support
v0.9.0
- [ ] Add e2e tests
- [ ] Web support
- [ ] Implement a non-blocking async API for writing large values to storage without blocking the JS thread
- [x] Implement async multiGet & multiSet functions for intensive read/write
- [x] Improve state updates. provide a state selector or do shallow compare internally
Anything else.. drop a comment below and we can discuss
Is there currently a way to retrieve all key/value pairs like in AsyncStorage, which was used to migrate to MMKV? That may be helpful.
@robkainz Just use storageInstance.indexer
.
Mocks for Jest please 🙏
@ahmedu007 in progress
@ahmedu007 jest mocks shipped in v0.7.0
For first thanks for your work. ❤️❤️ Btw. I tried to use this package with the new expo-modules, expo sdk 44+ but I always get an error that mmkv package can not be found. I use rn bare workflow with some expo package. There is any futher steps to use them together?
@dancixx Did you run expo prebuild
? Also can you share the exact error that you are getting?
@ammarahm-ed yes I run it, but got the same error, but I think the error is on my side, so I will drop the expo in the near future. Maybe I give it one more chance for it this weekend I write the result.
Hi, I have a strange error when I try to store a map as a value in MMKV storage. After saving a map and reopening the app, the map is empty, but the strings I stored in other keys are there. Is this a known issue?
Hi, I have a strange error when I try to store a map as a value in MMKV storage. After saving a map and reopening the app, the map is empty, but the strings I stored in other keys are there. Is this a known issue?
Convert map to simple object before saving in storage.
Thank you, that works.
Will there be support for react-native-windows? As it is a c++ lib, maybe be an easy addition to this repo! :)
Hi,
Would be nice to have support for groupId when initializing mmkv. Recently got it to work with the help I got from @ammarahm-ed , but I still need to test encrypted store.
Also how would you support web? by replacing with local storage?
@humaidk2 For web, we will use local-forage
and only expose an async API. A sync wrapper around localStorage is possible but not very performant with no support for encryption. It's WIP.
groupId can be supported but only through adding a value to info.plist
file which will be the simplest and best way. Doing it through JS won't be safe.
Wow I didn't know about local-forage,
I don't mean to ask too many questions here but what if the data can't be stored on web. Since web is really limited compared to mmkv. Technically, the developer could create a smaller web mmkv instance and migrate data through that.
info.plist sounds like a cool plan, considering the bundle id is already there, it would be easier to differentiate between build flavors too.
Also I'm guessing for e2e, you're looking to use detox? I do recommend it, it seems the build problems are gone and it's working well with latest react native.
@humaidk2 local-forage is quite close to mmkv in architecture with support for multiple instances etc. The only difference is that mmkv is fully sync while local-forage is async storage. Hence the limitation of web to only use async methods while use localStorage for the sync API with a warning. There's already a branch were I am working on the implementation.
And yes, detox would be it.
🙏🙏 Please add an equalityFn like useSelector of react-redux in useMMKVStorage hook.
const result: any = useSelector(selector: Function, equalityFn?: Function)
It helps to reduce unnecessary re-rendering of component when value is not changed.
@djintalkalan will add this.
Hi @ammarahm-ed, I published Flipper plugin for this library, you can add it to somewhere in your document website.
@pnthach95 That's great! I will update the docs once in release v0.8.0 this Sunday.
would love it if we can add ttl type of expiration to the keys.
@crypt0miester What is the use-case for it
@crypt0miester What is the use-case for it
caching would be a good use case.
Implement a non-blocking async API for writing large values to storage without blocking the JS thread Implement async multiGet & multiSet functions for intensive read/write
Those 2 things would be so dope !
Using react-native-mmkv-storage for react-redux and it can be very huge amount of data sometimes
Edit just saw we already have it, perfect 😄
Implement a non-blocking async API for writing large values to storage without blocking the JS thread Implement async multiGet & multiSet functions for intensive read/write
Those 2 things would be so dope !
Using react-native-mmkv-storage for react-redux and it can be very huge amount of data sometimes
Edit just saw we already have it, perfect 😄
You can try async get/set for items in bulk in the latest alpha, v0.10.0
Implement a non-blocking async API for writing large values to storage without blocking the JS thread Implement async multiGet & multiSet functions for intensive read/write
Those 2 things would be so dope !
Using react-native-mmkv-storage for react-redux and it can be very huge amount of data sometimes
Edit just saw we already have it, perfect 😄
You can try async get/set for items in bulk in the latest alpha, v0.10.0. Haven't added multiGet/multiSet polyfills yet but we have setMultipleItemsAsync/getMultipleItemsAsync which do most of the work off the js thread by default.
Yeah saw about the setMultipleItemsAsync/getMultipleItemsAsync.
Thank you very much, this is a very good library 👍
Thanks @ammarahm-ed for the great work on this package. I have a couple of questions:
- Do the *Async functions leverage native threads? Are they non-blocking, or is this still being developed?
- Is there a web implementation in v10 (alpha)? Couldn't find it. Might go with
idb-keyval
for similar Async functionality for Web if it's not available since both APIs look quite similar (using *Async).
Cheers.
I've noticed that the Async methods currently serve as wrappers over regular methods.
https://github.com/ammarahm-ed/react-native-mmkv-storage/blob/5c653b745b1c30da16bc12dac665e393a1807a07/src/mmkvinstance.ts#L81
@ammarahm-ed , in the evolution of this package, is there a plan to integrate native async calls into these wrappers in future updates?
Also, I'd like to ask if this package could be used to store binary data compactly (without serializing to strings)?
thanks for great library, please consider adding web support