React Native Storage - v2.0.0
    Preparing search index...

    React Native Storage - v2.0.0

    React Native Storage

    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)} />;
    }
    • createStorage creates a storage on top of a driver, with an optional namespace.
    • Storage.item declares a typed value: default value, schema, TTL, version and migrations.
    • StorageItem reads and writes it: get, set, remove, subscribe.
    • useStorageItem shows it in a component.
    • StorageError is the one error type; its code says what went wrong.

    The source, the example app and the issue tracker are on GitHub.