33[ ![ npm] ( https://img.shields.io/npm/v/react-native-nitro-storage )] ( https://www.npmjs.com/package/react-native-nitro-storage )
44[ ![ MIT license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( LICENSE )
55[ ![ React Native] ( https://img.shields.io/badge/react--native-%3E%3D0.75-61dafb )] ( https://reactnative.dev/ )
6- [ ![ Nitro Modules] ( https://img.shields.io/badge/nitro--modules-%3E%3D0.35.4 -black )] ( https://nitro.margelo.com/ )
6+ [ ![ Nitro Modules] ( https://img.shields.io/badge/nitro--modules-%3E%3D0.35.5 -black )] ( https://nitro.margelo.com/ )
77
88One storage layer for render-time state, persisted app state, and native secrets.
99
@@ -42,6 +42,7 @@ Use it when you want one storage API for React Native and web, with fast synchro
4242| Move existing MMKV data | ` migrateFromMMKV ` |
4343| Persist storage on web | ` setWebDiskStorageBackend ` or ` createIndexedDBBackend ` |
4444| Inspect secure backend state | ` getSecurityCapabilities ` , ` getSecureMetadata ` , metadata APIs |
45+ | Connect external state/debug code | ` subscribeNamespace ` , ` subscribePrefix ` , ` setEventObserver ` |
4546
4647## Use It When
4748
@@ -56,7 +57,7 @@ Use a database or server-state cache instead when you need relational queries, c
5657- Three scopes: in-memory session state, persisted disk state, and platform secure storage.
5758- Secure storage backed by iOS Keychain and Android Keystore/EncryptedSharedPreferences.
5859- React hooks without providers: ` useStorage ` , ` useStorageSelector ` , and ` useSetStorage ` .
59- - Batch reads/writes, namespace cleanup, raw import/export, transactions, and migrations.
60+ - Batch reads/writes, namespace cleanup, raw import/export, event subscriptions, transactions, and migrations.
6061- Web parity with configurable Disk/Secure backends and an IndexedDB backend.
6162- MMKV migration helper for moving existing keys without rewriting app code first.
6263
@@ -188,6 +189,37 @@ runTransaction(StorageScope.Disk, (tx) => {
188189});
189190```
190191
192+ Create a raw snapshot for backups or test fixtures, then restore it later:
193+
194+ ``` ts
195+ import { StorageScope , storage } from " react-native-nitro-storage" ;
196+
197+ const snapshot = storage .export (StorageScope .Disk );
198+
199+ storage .import (snapshot , StorageScope .Disk );
200+ ```
201+
202+ ` storage.export(StorageScope.Secure) ` returns raw secret values. Do not log Secure exports or include them in diagnostics, analytics, crash reports, or support bundles.
203+
204+ Subscribe to storage changes outside React:
205+
206+ ``` ts
207+ import { StorageScope , storage } from " react-native-nitro-storage" ;
208+
209+ const unsubscribe = storage .subscribeNamespace (
210+ " settings" ,
211+ StorageScope .Disk ,
212+ (event ) => {
213+ if (event .type === " batch" ) {
214+ console .log (" settings changed" , event .changes .length );
215+ return ;
216+ }
217+
218+ console .log (event .key , event .operation );
219+ },
220+ );
221+ ```
222+
191223## Storage Scopes
192224
193225| Scope | Backing store | Best for |
@@ -243,7 +275,7 @@ import {
243275The main building blocks are:
244276
245277- ` createStorageItem<T>(config) ` for typed values.
246- - ` storage ` for raw reads, namespace cleanup, secure metadata, metrics, and runtime capability checks.
278+ - ` storage ` for raw reads, namespace cleanup, events, secure metadata, metrics, and runtime capability checks.
247279- ` getBatch ` , ` setBatch ` , and ` removeBatch ` for multi-key work.
248280- ` runTransaction ` for synchronous rollback on failure.
249281- ` registerMigration ` and ` migrateToLatest ` for versioned local data migrations.
@@ -265,7 +297,7 @@ Peer dependencies:
265297
266298- ` react >=18.2.0 `
267299- ` react-native >=0.75.0 `
268- - ` react-native-nitro-modules >=0.35.4 `
300+ - ` react-native-nitro-modules >=0.35.5 `
269301
270302## Security Model
271303
@@ -355,9 +387,11 @@ bun run format:check -- --filter=react-native-nitro-storage
355387bun run typecheck -- --filter=react-native-nitro-storage
356388bun run test:types -- --filter=react-native-nitro-storage
357389bun run test -- --filter=react-native-nitro-storage
390+ bun run test:coverage -- --filter=react-native-nitro-storage
358391bun run test:cpp -- --filter=react-native-nitro-storage
392+ bun run test:cpp:coverage -- --filter=react-native-nitro-storage
359393bun run --cwd packages/react-native-nitro-storage check:pack
360- npm publish --dry-run
394+ bun run publish-package:dry -- --yes --with-coverage
361395```
362396
363397## Development
@@ -378,7 +412,7 @@ Release checks:
378412bun run build -- --filter=react-native-nitro-storage
379413bun run benchmark -- --filter=react-native-nitro-storage
380414bun run --cwd packages/react-native-nitro-storage check:pack
381- npm publish --dry-run
415+ bun run publish-package:dry -- --yes
382416```
383417
384418## License
0 commit comments