createStorage function is a factory that creates custom storage instances. Use this when you need multiple storage configurations or want to customize global serialization behavior.
Import
Usage
Basic Custom Storage
Custom Serialization
Custom MMKV Instance (React Native)
Signature
Parameters
Configuration options for the storage instance.
Returns
AStorage function that can be called with (initialValue, options?) to create persisted state values.
Examples
Multiple Storage Instances
Custom Serialization Library
Binary Serialization
Encrypted Storage (React Native)
Multiple MMKV Instances
Per-Value Options Override
TypeScript
The storage instance is fully typed and infers types from usage:Platform Differences
Web Implementation
- Located at
stan-js/storage/factory.ts - Uses
localStorageAPI - Includes SSR safety checks
- Falls back to in-memory Map when localStorage unavailable
- Supports cross-tab synchronization
React Native Implementation
- Located at
stan-js/storage/mmkvFactory.ts - Uses
react-native-mmkvlibrary - Supports both MMKV v2 and v3
- Does not support cross-instance synchronization
- Faster and more reliable than AsyncStorage
Related
storage
Pre-configured storage wrapper
MMKV Integration
React Native MMKV setup and configuration
Synchronizer Type
TypeScript interface for custom synchronizers
Persistence Guide
Complete guide to data persistence patterns