Typed key-value storage for React Native and Expo. Declare each value once with a name, a
default value and, if you like, a schema; then read and write it from anywhere, or show it in a
component with useStorageItem. The values are saved by a driver you choose: MMKV,
AsyncStorage, SecureStore, localStorage or memory.
import { createMMKV } from 'react-native-mmkv';
import { createStorage, mmkvDriver } from 'react-native-storage-toolkit';
import { useStorageItem } from 'react-native-storage-toolkit/react';
const storage = createStorage({ driver: mmkvDriver(createMMKV()) });
const pressCount = storage.item('press-count', { defaultValue: 0 });
function PressCounter() {
const [count, setCount] = useStorageItem(pressCount);
return <Button title={`Pressed ${count} times`} onPress={() => setCount((n) => n + 1)} />;
}
get, set, remove, subscribe.code says what went wrong.The source, the example app and the issue tracker are on GitHub.