├── .DS_Store ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── build ├── ReactNativeUserDefaults.d.ts ├── ReactNativeUserDefaults.d.ts.map ├── ReactNativeUserDefaults.ios.d.ts ├── ReactNativeUserDefaults.ios.d.ts.map ├── ReactNativeUserDefaults.ios.js ├── ReactNativeUserDefaults.ios.js.map ├── ReactNativeUserDefaults.js ├── ReactNativeUserDefaults.js.map ├── index.d.ts ├── index.d.ts.map ├── index.js └── index.js.map ├── expo-module.config.json ├── ios ├── ReactNativeUserDefaults.podspec └── ReactNativeUserDefaultsModule.swift ├── package.json ├── src ├── ReactNativeUserDefaults.ios.ts ├── ReactNativeUserDefaults.ts └── index.ts ├── tsconfig.json └── yarn.lock /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrew-levy/react-native-userdefaults/6526a494c6e3f72e14609c64e6dd8089ef6e028a/.DS_Store -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: ['universe/native', 'universe/web'], 4 | ignorePatterns: ['build'], 5 | }; 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UserDefaults 2 | 3 | An interface to the user’s defaults database, where you store key-value pairs persistently across launches of your app. Inspired by [UserDefaults](https://developer.apple.com/documentation/foundation/userdefaults). 4 | 5 | - :white_check_mark: Built with [Expo's Module API](https://docs.expo.dev/modules/module-api/) 6 | - :white_check_mark: Written in TypeScript and Swift 7 | - :apple: Currently iOS only 8 | 9 | ## Installation 10 | 11 | 1. Install the package 12 | 13 | ```console 14 | yarn add @alevy97/react-native-userdefaults 15 | ``` 16 | 17 | 2. Install pods 18 | 19 | ```console 20 | npx pod-install 21 | ``` 22 | 23 | ## Usage 24 | 25 | ### Standard Defaults 26 | 27 | The most common use case for using `UserDefaults` is to store small chunks of data to the standard defaults system. You can access the standard defaults system using the static property `UserDefaults.standard` or by creating a new `UserDefaults` instance. 28 | 29 | ```tsx 30 | UserDefaults.standard; 31 | ``` 32 | 33 | or equivalently 34 | 35 | ```tsx 36 | new UserDefaults(); 37 | ``` 38 | 39 | ### Defaults with Suite Name 40 | 41 | UserDefaults can also be used to store data that can be shared across multiple apps belonging to the same [App Group](https://developer.apple.com/documentation/xcode/configuring-app-groups?changes=_3), also known as a suite. To achieve this, provide a suite name (app group identifier) when creating a `UserDefaults` instance. 42 | 43 | ```tsx 44 | new UserDefaults("group.com.example.app"); 45 | ``` 46 | 47 | ### Example 48 | 49 | ```tsx 50 | import { Button, View } from "react-native"; 51 | import UserDefaults from "@alevy97/react-native-userdefaults"; 52 | 53 | const standardDefaults = UserDefaults.standard; // or new UserDefaults() 54 | const groupDefaults = new UserDefaults("group.com.example.app"); 55 | 56 | function App() { 57 | return ( 58 | 59 |