react-native-cross-settings
React Native Settings
module for both Android & iOS.
If this library has helped you, don't forget to give it a star 🌟
Important
v2.1.0 works with Gradle 4.10.x, the default in React Native 0.58. If you are using Gradle 3.x please use react-native-cross-settings 1.0.2
Setup
yarn add react-native-cross-settingsreact-native link react-native-cross-settings
Usage
; // Set a listener. It will be called for *each* value that has changed.const watchId = Settings; // If you never saved a value in "strvar", this is undefined.console;// => undefined // Store a value (only string, number, or boolean)Settings;console;// => "First setting" // You cann't remove a value, but you can set it to null.// Next time your App start, the value will be undefined.Settings;console;// => null // Store a new value, this will be preserved across sessions.Settings; // => Don't forget to remove the listenerSettings
API
See React Native Settings page, the API is the same.
Methods
-
get()
static getkey: string number | string | value | null -
set()
static setsettings: void -
watchKeys()
static watchKeyskeys: string | string, callback:any number -
clearWatch()
static clearWatchwatchId: number void
NOTE
In Android, valid value types to store are boolean
, string
, and number
.
If you pass null
as value, the key will be removed in the next session.
If you want to save other types use the appropriate conversion:
// Storing a Date object:Settings// Retrieveconst myDate = Settings // Storing an arraySettings// Retrieveconst myArray = JSON
Support my Work
I'm a full-stack developer with more than 20 year of experience and I try to share most of my work for free and help others, but this takes a significant amount of time and effort so, if you like my work, please consider...
Of course, feedback, PRs, and stars are also welcome 🙃
Thanks for your support!
License
The MIT License (MIT)