Registry / storage / react-native-session-storage

react-native-session-storage

JSON →
library2.0.4jsnpmunverified

A session-bound volatile storage module for React Native, similar to browser sessionStorage. v2.0.4 supports iOS, Android, and Web, with TypeScript types included. Data is automatically cleared when the app is re-opened. Provides simple key-value API (setItem, getItem, removeItem, clear, key, length) plus advanced multiGet and getAllItems. Lightweight, no native dependencies required for Web, and can be used with Expo. Not a replacement for persistent storage like AsyncStorage.

npm install react-native-session-storage
INSTALL
IMPORT
SIG · REACT-NATIVE-SESSI
R
react-native-session-storage
storagejavascriptv2.0.4
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.

default
import SessionStorage from 'react-native-session-storage'
import { SessionStorage } from 'react-native-session-storage'
Default import only; named import does not exist.
type
import type { SessionStorage } from 'react-native-session-storage'
import { SessionStorage } from 'react-native-session-storage'
If you need the type, use import type to avoid bundling issues.
require
const SessionStorage = require('react-native-session-storage').default
const SessionStorage = require('react-native-session-storage')
CommonJS require pattern must access .default property.

Demonstrates basic CRUD operations (setItem, getItem, removeItem, clear, length) and advanced multiGet/getAllItems using default import.

import SessionStorage from 'react-native-session-storage'; // Store a value SessionStorage.setItem('user', { name: 'Alice' }); // Retrieve a value const user = SessionStorage.getItem('user'); console.log(user); // { name: 'Alice' } // Get length console.log(SessionStorage.length); // 1 // Remove a specific item SessionStorage.removeItem('user'); // Clear all SessionStorage.clear(); // Advanced: multiGet SessionStorage.setItem('a', 1); SessionStorage.setItem('b', 2); const multi = SessionStorage.multiGet(['a', 'b']); console.log(multi); // { a: 1, b: 2 } // Get all items SessionStorage.setItem('x', { foo: 'bar' }); const all = SessionStorage.getAllItems(); console.log(all); // { x: { foo: 'bar' } }
Debug
Known issues
gotchaData is cleared when app is reopened. Do not rely on it for persistence.
fix
Use AsyncStorage or react-native-mmkv for persistent storage.
affects: >=0.0.0
gotchasetItem accepts any value (not just strings) but it may be serialized/deserialized internally. Ensure values are JSON-serializable.
fix
Pass only strings, numbers, booleans, objects, or arrays.
affects: >=0.0.0
gotchamultiGet returns a record with the same keys; if a key does not exist, its value is undefined.
fix
Check for undefined values after calling multiGet.
affects: >=0.0.0
Errors
Common errors & fixes
undefined is not an object (evaluating 'SessionStorage.setItem')
Using default import without .default in CommonJS environment (e.g., Jest).
fix
Use `const SessionStorage = require('react-native-session-storage').default;`
'SessionStorage' is not exported from 'react-native-session-storage'
Attempting named import when only default export exists.
fix
Use `import SessionStorage from 'react-native-session-storage'`
Cannot read property 'clear' of undefined
The module was not initialized correctly; maybe using a non-standard bundler.
fix
Ensure the module is properly linked in React Native (if using bare workflow) or use Expo SDK 49+.
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies
react-nativerequiredRequires React Native runtime for native platform implementation
Agent activity
15 hits · last 30 days
node
14
Resources
react-native-session-storage — npm install react-native-session-storage · libregistry