Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing UserPreferences with a React Native App

Tags:

react-native

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

like image 654
rajasaur Avatar asked May 01 '15 14:05

rajasaur


People also ask

Does Localstorage work in React Native?

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 we use React Native library for web development?

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.


4 Answers

You may try AsyncStorage instead?

like image 145
Menway Avatar answered Oct 11 '22 18:10

Menway


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

:)

like image 41
Dave Sibiski Avatar answered Oct 11 '22 18:10

Dave Sibiski


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.

  • Github: https://github.com/wwayne/react-native-user-defaults
  • NPM: https://www.npmjs.com/package/react-native-user-defaults
like image 32
wwayne Avatar answered Oct 11 '22 19:10

wwayne


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"))
})
like image 44
olivia Avatar answered Oct 11 '22 18:10

olivia