Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sriraman/react-native-shared-preferences
Android's Native key value storage system in React Native
https://github.com/sriraman/react-native-shared-preferences
android react-native shared-preferences storage
Last synced: about 1 month ago
JSON representation
Android's Native key value storage system in React Native
- Host: GitHub
- URL: https://github.com/sriraman/react-native-shared-preferences
- Owner: sriraman
- Created: 2016-05-14T02:19:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-09-13T05:59:37.000Z (over 3 years ago)
- Last Synced: 2024-04-26T02:34:22.904Z (9 months ago)
- Topics: android, react-native, shared-preferences, storage
- Language: Java
- Size: 118 KB
- Stars: 125
- Watchers: 6
- Forks: 54
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-react-native - react-native-shared-preferences ★85 - Android's Native key value storage system in React Native (Components / UI)
- awesome-reactnative-ui - react-native-shared-preferences
- awesome-react-native - react-native-shared-preferences ★85 - Android's Native key value storage system in React Native (Components / UI)
- awesome-reactnative-ui - react-native-shared-preferences
- awesome-react-native - react-native-shared-preferences ★85 - Android's Native key value storage system in React Native (Components / UI)
- awesome-react-native-ui - react-native-shared-preferences ★36 - Android's Native key value storage system in React Native (Components / UI)
- awesome-react-native - react-native-shared-preferences ★85 - Android's Native key value storage system in React Native (Components / UI)
README
# React Native Shared Preferences
Android's Native key value storage system in React Native
## Installation
### < RN 0.47
```bash
npm install [email protected] --save
```### >= RN 0.47
```bash
npm install react-native-shared-preferences --save
```## Project setup and initialization
* In `android/settings.gradle`
```gradle
...
include ':react-native-shared-preferences', ':app'
project(':react-native-shared-preferences').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-shared-preferences/android')
```* In `android/app/build.gradle`
```gradle
...
dependencies {
/* YOUR DEPENDENCIES HERE */
compile "com.facebook.react:react-native:+"
compile project(":react-native-shared-preferences") // <--- add this
}```
* Register Module (in MainApplication.java)
```java
import in.sriraman.sharedpreferences.RNSharedPreferencesReactPackage; // <--- importpublic class MainActivity extends ReactActivity {
......@Override
protected List getPackages() {
return Arrays.asList(
new MainReactPackage(),
new RNSharedPreferencesReactPackage() // <--- Add this
);
}......
}
```## Usage
#### Import
```javascript
var SharedPreferences = require('react-native-shared-preferences');
```#### Configure name of preferences file. (Optional. Must be called before other functions.)
```javascript
SharedPreferences.setName("name");
```#### Set Item
```javascript
SharedPreferences.setItem("key","value");
```#### Get an value
```javascript
SharedPreferences.getItem("key", function(value){
console.log(value);
});
```#### Get multiple items
```javascript
SharedPreferences.getItems(["key1","key2"], function(values){
console.log(values)
});
```#### Get all values
```javascript
SharedPreferences.getAll(function(values){
console.log(values);
});
```#### Clear all values
```javascript
SharedPreferences.clear();
```#### Get all keys - returns promise with array of keys
```javascript
SharedPreferences.getAllKeys(function(keys){
console.log(keys);
});
```#### Remove Item
```javascript
SharedPreferences.removeItem("key");
```## Credits
[Sujith Niraikulathan](http://bit.ly/sujithkanna "Sujith").