Skip to main content
Settings is iOS-only. On other platforms, it has no effect.
The Settings API provides access to iOS app settings stored in NSUserDefaults. It allows reading and writing settings values and observing changes to specific settings keys.

Import

Methods

get()

Get the value for a given settings key. Parameters:
  • key: The settings key to retrieve
Returns: The value stored for the key, or undefined if not found.

Example

set()

Set multiple settings values at once. Parameters:
  • settings: An object containing key-value pairs to store
The set() method updates the local cache and persists values to NSUserDefaults.

Example

watchKeys()

Watch for changes to specific settings keys. Parameters:
  • keys: A single key string or array of key strings to watch
  • callback: Function called when any watched key changes
Returns: A watch ID that can be used with clearWatch() to unsubscribe.

Example

clearWatch()

Remove a settings key watcher. Parameters:
  • watchId: The watch ID returned by watchKeys()

Example

Usage Examples

Basic Settings Management

Watching Settings Changes

Multiple Settings

User Preferences Hook

Persisting App State

Notes

  • Settings only works on iOS and uses NSUserDefaults internally.
  • Values are automatically persisted across app launches.
  • Supported value types include strings, numbers, booleans, and objects (serializable to JSON).
  • Changes made via set() trigger callbacks registered with watchKeys().
  • The callback receives no arguments; use get() to retrieve updated values.
  • Watch IDs are integers starting from 0.
  • It’s important to call clearWatch() in cleanup functions to prevent memory leaks.
  • For cross-platform settings storage, consider using AsyncStorage or a third-party solution.
  • Settings are app-specific and not shared between apps.