ammarahm-ed / react-native-mmkv-storage

An ultra fast (0.0002s read/write), small & encrypted mobile key-value storage framework for React Native written in C++ using JSI
https://rnmmkv.now.sh
MIT License
1.6k stars 111 forks source link

Best pattern for sharing data between components using useMMKVStorage? #228

Closed siderakis closed 2 years ago

siderakis commented 2 years ago

What are the pros/cons of fetching same data in different components using multiple calls to useMMKVStorage compared to passing the data/setter function as a prop from a component higher up the component tree?

I haven't tested it but making multiple calls to useMMKVStorage for the same data opens up the potential to call it with different default values. This seems like a minor reason to favor passing down the data/setters.

ammarahm-ed commented 2 years ago

@siderakis You can pass the default value in one of the components only. The rest will automatically take up that value. This feature is available in the master branch for now.

npm install https://github.com/ammarahm-ed/react-native-mmkv-storage

At initialization you must call new MMKVStorage.Loader().withPersistedDefaultValues().initialize()