Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including react-native-shared-group-preferences with all npm packages installed. Try it out:

require("react-native/package.json"); // react-native is a peer dependency. var reactNativeSharedGroupPreferences = require("react-native-shared-group-preferences")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-native-shared-group-preferences v1.1.24

#### To Know - Doesn't work for Expo since this uses native code. - iOS & Android ONLY - Uses Xcode's Shared Preferences App Groups (iOS) and Public External Storage for Android. - Once you install via npm, you will need to do some configuration in Xcode for your javascript to access a shared group container. Android will need Permissions. - I tried to model this after React Native's AsyncStorage. Main thing is that you no longer need to do JSON.stringify and JSON.parse when you set/get. Not sure why they make you do that to begin with... but you can set/get an JSONable item using this module. - All methods return a promise. So make sure to make your functions async. - iOS's data is securely sandboxed within your app group. I couldn't find something as easy to access, or that wouldn't be deleted if you delete an app, so the Android version saves a json file to the android device's external storage. This is good because if the app is deleted, another app can still access the data. But this is bad because any other app can delete/edit/access this file. For this reason, at least for Android, do not store data in it that is sensitive. If you're saving user preferences, fine. But do not save something like credit card numbers or anything like that in here. That would be irresponsible. The file is saved to the user's storage in the following format: ```$storage/$appGroupIdentifier/data.json```. So make sure your appGroupIdentifier is a valid folder name. Reverse dns works fine.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free