Coder Social home page Coder Social logo

prokure / react-native-shared-preferences Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sriraman/react-native-shared-preferences

1.0 2.0 0.0 115 KB

Android's Native key value storage system in React Native

JavaScript 21.43% Java 43.92% Python 8.28% Objective-C 26.37%

react-native-shared-preferences's Introduction

React Native Shared Preferences

Android's Native key value storage system in React Native

Installation

< RN 0.47

npm install [email protected] --save

>= RN 0.47

npm install react-native-shared-preferences --save

Project setup and initialization

  • In android/settings.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
...
dependencies {
    /* YOUR DEPENDENCIES HERE */
    compile "com.facebook.react:react-native:+"
    compile project(":react-native-shared-preferences") // <--- add this
}
  • Register Module (in MainApplication.java)
import in.sriraman.sharedpreferences.RNSharedPreferencesReactPackage;  // <--- import

public class MainActivity extends ReactActivity {
  ......

  @Override
  protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNSharedPreferencesReactPackage() // <--- Add this
      );
  }

  ......

}

Usage

Import

var SharedPreferences = require('react-native-shared-preferences');

Set Item

SharedPreferences.setItem("key","value");

Get an value

SharedPreferences.getItem("key", function(value){
  console.log(value);
});

Get multiple items

SharedPreferences.getItems(["key1","key2"], function(values){
  console.log(values)
});

Get all values

SharedPreferences.getAll(function(values){
  console.log(values);
});

Clear all values

SharedPreferences.clear();

Get all keys - returns promise with array of keys

SharedPreferences.getAllKeys(function(keys){
  console.log(keys);
});

Remove Item

SharedPreferences.removeItem("key");

Credits

Sujith Niraikulathan.

react-native-shared-preferences's People

Contributors

sriraman avatar nhayfield avatar sujithkanna avatar steffeydev avatar opengeekslab avatar

Stargazers

Dmitry Volkov avatar

Watchers

James Cloos avatar Shubham Agrawal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.