I'm trying to run a few examples using react-native and was curious to see how to store User Preferences using NSUserDefaults with React Native.
Would we have to implement a module that exports the NSUserDefaults method as mentioned here
To store value in local storage in React Native, we can use AsyncStorage. to call AsyncStorage. setItem with the key and value to storage the entry with the key and value. Then we call AsyncStorage.
Can React Native be used for web and mobile? Yes! With React Native for Web, developers can write a single React Native application that can run natively on Android and iOS, as well as on a web browser using standard web technologies.
You may try AsyncStorage instead?
I created a bridge module that interfaces with NSUserDefaults. If you still wanted or needed it (ie. you have an existing app that uses NSUserDefaults already), check it out: https://github.com/dsibiski/react-native-userdefaults-ios
:)
I've created a component to use of NSUserDefaults, it have set
and get
method, much easy to use, suits for storing those small, insensitive and permanent info or user preferences.
React native has it own serves wrapped UserDefaults, official site link
import {Setting} from from 'react-native';
const name = Settings.get("your_id_key_can_get_from_setting_bundle");
console.log(name);
Settings.watchKeys('your_id_key', () => {
console.log(Settings.get("your_id_key"))
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With