Registry / storage / react-native-shared-preferences

react-native-shared-preferences

JSON →
library1.0.2jsnpmunverified

A React Native bridge to Android's native SharedPreferences key-value storage. Version 1.0.2 is stable but unmaintained since 2018. It provides synchronous and callback-based get/set operations, with support for getting multiple items and all keys. This library requires manual linking and is intended for Android only, unlike cross-platform alternatives like @react-native-async-storage/async-storage. It is suitable for legacy RN projects (<0.60) that do not use autolinking.

npm install react-native-shared-preferences
INSTALL
IMPORT
SIG · REACT-NATIVE-SHARE
R
react-native-shared-preferences
storagejavascriptv1.0.2
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 export
const SharedPreferences = require('react-native-shared-preferences');
import SharedPreferences from 'react-native-shared-preferences';
Package does not ship ES modules; only CommonJS require works.
setName
SharedPreferences.setName('myPrefs');
SharedPreferences.setName = 'myPrefs';
setName is a function, not a setter. Must be called before other methods.
setItem
SharedPreferences.setItem('key', 'value');
SharedPreferences.setItem('key', 'value', callback);
setItem does not accept a callback; it is synchronous on the native side.

Shows basic usage: import, set name, set a string, and retrieve it via callback.

const SharedPreferences = require('react-native-shared-preferences'); SharedPreferences.setName('userPrefs'); SharedPreferences.setItem('username', 'alice'); SharedPreferences.getItem('username', (value) => { console.log('Username:', value); });
Debug
Known issues
deprecatedPackage is unmaintained and deprecated. Use @react-native-async-storage/async-storage instead.
fix
Migrate to @react-native-async-storage/async-storage or expo-secure-store.
affects: >=1.0.0
breakingAndroid only; calling any method on iOS will throw an error or do nothing.
fix
Wrap calls in Platform.OS === 'android' checks or use a cross-platform library.
affects: all
gotchaRequires manual linking for React Native <0.60. Autolinking is not supported.
fix
Follow manual linking steps in README or use react-native link.
affects: all
gotchasetName must be called before any get/set operations; otherwise default SharedPreferences file is used.
fix
Call setName early in app initialization.
affects: all
gotchagetItems and getAllKeys callbacks receive values/keys as array-like objects, not standard arrays.
fix
Use Array.from() or spread operator to convert.
affects: >=1.0.0
Errors
Common errors & fixes
undefined is not an object (evaluating 'SharedPreferences.setItem')
SharedPreferences is not properly linked or imported.
fix
Ensure manual linking steps are followed, or use react-native link react-native-shared-preferences.
Cannot read property 'getAllKeys' of undefined
setName not called or called after other methods.
fix
Call SharedPreferences.setName('yourName') before any get/set operation.
Module 'react-native-shared-preferences' does not export a default
Using ES import syntax with a CommonJS-only module.
fix
Change to const SharedPreferences = require('react-native-shared-preferences');
TypeError: SharedPreferences.getAll is not a function
Typo: method is getItems, not getAll.
fix
Use SharedPreferences.getItems(keys, callback) for multiple keys, or getAllKeys(callback) for all keys.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
react-nativerequiredNative module requires React Native runtime
Agent activity
16 hits · last 30 days
node
14
Amazon
1
Resources
react-native-shared-preferences — npm install react-native-shared-preferences · libregistry