react-native-shared-preferences-modify
v1.0.2
Published
Android's Native key value storage system in React Native
Downloads
1
Maintainers
Readme
React Native Shared Preferences
Android's Native key value storage system in React Native
Installation
>= RN 0.47
npm install react-native-shared-preferences-android --save
Project setup and initialization
- In
android/settings.gradle
...
include ':react-native-shared-preferences-android', ':app'
project(':react-native-shared-preferences-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-shared-preferences-android/android')
- In
android/app/build.gradle
...
dependencies {
/* YOUR DEPENDENCIES HERE */
compile "com.facebook.react:react-native:+"
compile project(":react-native-shared-preferences-android") // <--- 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(),
);
}
......
}
Usage
Import
var SharedPreferences = require("react-native-shared-preferences-android");
Configure name of preferences file. (Optional. Must be called before other functions.)
Set Item
SharedPreferences.setItem("key", "value", "nameFile");
Get an value
SharedPreferences.getItem("key", function (value), {
console.log(value);
});
Clear all values
SharedPreferences.clear();
Remove Item
SharedPreferences.removeItem("key");