React Native

Usage of Legend-State in React Native is exactly that same as in React, so see the React guides. But React Native uses different persistence:

Persistence with mmkv

Legend-State includes a local persistence plugin for React Native that uses react-native-mmkv. Install it first:

npm
yarn
npm i react-native-mmkv

Then you can configureObservablePersistence with it:

import { ObservablePersistMMKV } from '@legendapp/state/mmkv'
import { configureObservablePersistence } from '@legendapp/state/persist'

// Global configuration
configureObservablePersistence({
    // Use react-native-mmkv in React Native
    persistLocal: ObservablePersistMMKV
})

And now when you use persistObservable it will persist to device storage using react-native-mmkv. For more information see Persistence.