Registry / storage / react-native-storage

react-native-storage

JSON →
library1.0.1jsnpmunverified

A local storage wrapper for react-native and web apps, providing a unified API over AsyncStorage (React Native) and localStorage (browser). Version 1.0.1 is the latest stable release, with no active development since 2019. It uses ES6 syntax, promises for async loading, and supports memory caching, expiration, and automatic synchronization via custom sync methods. Key differentiators include cross-platform compatibility, configurable size limits, and typed API via TypeScript definitions.

npm install react-native-storage
INSTALL
IMPORT
SIG · REACT-NATIVE-STORA
R
react-native-storage
storagejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Storage
import Storage from 'react-native-storage'
import { Storage } from 'react-native-storage'
Default import only; named import does not work.
AsyncStorage
import AsyncStorage from '@react-native-community/async-storage'
import AsyncStorage from 'react-native-storage'
AsyncStorage must be imported from its own package, not from react-native-storage.
Storage instance methods (save/load/remove)
storage.save({ key: 'key', data: 'value' })
Storage.save({ key: 'key', data: 'value' })
Methods are on the instance, not the class.

Shows initialization and basic save/load operations with async/await.

import Storage from 'react-native-storage'; import AsyncStorage from '@react-native-community/async-storage'; const storage = new Storage({ size: 1000, storageBackend: AsyncStorage, defaultExpires: 1000 * 3600 * 24, enableCache: true, }); async function example() { await storage.save({ key: 'user', data: { name: 'Alice' } }); const user = await storage.load({ key: 'user' }); console.log(user.name); } example();
Debug
Known issues
gotchaDo not use underscore ('_') in key names; it can cause issues with some backends.
fix
Use camelCase or hyphens instead of underscores.
affects: >=0.0.0
gotchaSaving data with the same key-id pair overwrites the oldest data when size limit is reached, not the entry with the same key-id.
fix
Be aware of the FIFO eviction policy; plan key usage accordingly.
affects: >=0.0.0
deprecatedThe 'syncInBackground' option is deprecated and may be removed in future versions.
fix
Use 'autoSync: true' with default behavior; avoid setting syncInBackground explicitly.
affects: >=0.0.0
gotchaIf 'storageBackend' is not set, data will be lost after app reload.
fix
Always provide a storageBackend (AsyncStorage for RN, window.localStorage for web).
affects: >=0.0.0
gotchaThe 'defaultExpires' default is 24 hours; setting to null makes data never expire, but may cause memory issues.
fix
Set defaultExpires explicitly (e.g., to null) if you want persistent storage.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Storage is not a constructor
Using named import { Storage } instead of default import.
fix
Replace import { Storage } from 'react-native-storage' with import Storage from 'react-native-storage'.
Cannot find module '@react-native-community/async-storage'
Missing peer dependency for React Native backend.
fix
Run npm install @react-native-community/async-storage and react-native link @react-native-community/async-storage.
storage.save is not a function
Calling save on the class instead of an instance.
fix
Create an instance first: const storage = new Storage({...}) then call storage.save().
Unhandled Promise Rejection: NotFoundError: key not found
Attempting to load a key that was never saved or was evicted.
fix
Use sync method in constructor to provide a fallback, or handle NotFoundError in catch.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@react-native-community/async-storagerequiredRequired as the storage backend for React Native apps; provides AsyncStorage implementation
Agent activity
13 hits · last 30 days
node
12
Resources
react-native-storage — npm install react-native-storage · libregistry