Settings module for both Android & iOS.
If this library has helped you, don't forget to give it a star 🌟
v2.0 works with Gradle 4.4, the default in React Native 0.57. If you are using Gradle 3.x please use react-native-cross-settings 1.0.2
yarn add react-native-cross-settingsreact-native link react-native-cross-settings
;// 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
See React Native Settings page, the API is the same.
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
In Android, valid value types to store are
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...
Feedback, PRs stars, and smiles are also welcome :)
Thanks for your support!
The MIT License (MIT)