The **High Performance Storage Adapter** for the Natify Framework. This package implements the `IAsyncStorage` interface using [react-native-mmkv](https://www.google.com/search?q=https://github.com/mamous/react-native-mmkv), which is roughly **30x faster*
npm install @natify/storage-mmkvThe High Performance Storage Adapter for the Natify Framework.
This package implements the IAsyncStorage interface using react-native-mmkv, which is roughly 30x faster than the standard AsyncStorage
Architectural Note: Although MMKV is synchronous by nature, this adapter wraps operations in Promises to maintain interchangeability with other IAsyncStorage implementations (like Keychain or filesystem-based storage).
Since this is an adapter, you must install both the package and its native driver (Peer Dependency) in your application.
Bash
```
pnpm add @natify/storage-mmkv react-native-mmkv
Bash
``
yarn add @natify/storage-mmkv react-native-mmkv
After installation, you must install the pods for iOS and rebuild your application since MMKV uses C++ JSI bindings.
Bash
``
cd ios && pod install && cd ..Rebuild the app
pnpm run android # or pnpm run ios
---
Register this adapter in your NatifyProvider configuration at the root of your application (App.tsx).
TypeScript
`
import { NatifyProvider } from '@natify/core';
import { MMKVAdapter } from '@natify/storage-mmkv';
import { AxiosHttpAdapter } from '@natify/http-axios';
// 1. Instantiate the adapter
// Optional: You can pass an instance ID for data isolation
const fastStorage = new MMKVAdapter('user-preferences');
// 2. Register in the config container
const config = {
// Register by specific name (recommended)
'storage-fast': fastStorage,
// Or register as the default 'storage' capability
'storage': fastStorage,
// ... other adapters
'http': new AxiosHttpAdapter()
};
export default function App() {
return (
);
}
`
---
Consume the storage anywhere in your components using the useAdapter hook. You don't need to import this package directly in your UI components, just use the Core interfaces.
Get the first available adapter that handles 'storage'.
TypeScript
`
import { useAdapter } from '@natify/core';
import { IAsyncStorage } from '@natify/core/interfaces';
const SettingsScreen = () => {
// Returns the default storage adapter
const storage = useAdapter
const saveTheme = async () => {
await storage.setItem('theme', 'dark');
};
};
`
If you registered it as 'storage-fast' in the config.
TypeScript
`
import { useAdapter } from '@natify/core';
import { IAsyncStorage } from '@natify/core/interfaces';
const CacheManager = () => {
// Explicitly request the fast storage (MMKV)
const fastStorage = useAdapter
const clearCache = async () => {
await fastStorage.clear();
};
};
`
---
This adapter fully implements IAsyncStorage.
| Method | Signature | Description |
| ------------ | -------------------------------------------------- | ------------------------------------------------- |
| getItem | getItem | Retrieves a value. Auto-parses JSON if possible. |setItem
| | setItem | Saves a value. Auto-stringifies objects/arrays. |removeItem
| | removeItem(key: string): Promise | Deletes a single key. |clear
| | clear(): Promise | Warning:Wipes all data in this MMKV instance. |
- Property: capability'storage'
- Value:
---
#### Error: MMKV JSI bindings are not installed
This means the native C++ code isn't linked.
1. Ensure you installed react-native-mmkv in your App's package.json.cd ios && pod install
2. Run .pnpm start --reset-cache
3. Kill the Metro Bundler and restart with cache reset: .pnpm run ios
4. Rebuild the app binary ( / pnpm run android).
#### Unable to resolve module react-native-mmkv
If using a Monorepo, ensure react-native-mmkv` is hoisted or installed in the app's dependencies, not just inside the adapter.