Skip to Content

useSettings

useSettings(options: object): UseSettingsResult

Defined in: src/react/useSettings.ts:117 

A React hook for managing user settings with automatic persistence using WatermelonDB.

Multiple components calling this hook with the same (database, walletAddress) share a single underlying fetch and observe subscription — without this deduplication, every consumer would pay an extra worker-bridge round-trip per mount and trigger WatermelonDB’s “raw object sent over the bridge” warning. See userSettingsStore.ts for the pool implementation.

The hook supports both the legacy modelPreference API (deprecated) and the new unified userPreference API that stores profile data, model preferences, and personality settings in a single table.

Parameters

ParameterTypeDescription

options

object

Configuration options

options.database

Database | null

The WatermelonDB instance. May be null while the database is not yet bound (e.g. during cold start / logged-out renders on mobile, where the wrapper holds null until the wallet resolves). When null, the hook is inert: userPreference/modelPreference are null, isLoading is false, and mutation callbacks reject with a clear error.

options.walletAddress?

string

‐

Returns

UseSettingsResult

An object containing settings state and methods

Example

import { Database } from '@nozbe/watermelondb'; import { useSettings } from '@anuma/sdk/react'; function SettingsComponent({ database }: { database: Database }) { const { userPreference, isLoading, setUserPreference, updateProfile, updatePersonality, } = useSettings({ database, walletAddress: '0x123...', // Auto-loads and migrates preference }); const handleProfileUpdate = async () => { await updateProfile('0x123...', { nickname: 'John', occupation: 'Developer', }); }; return ( <div> <p>Nickname: {userPreference?.nickname ?? 'Not set'}</p> <button onClick={handleProfileUpdate}>Update Profile</button> </div> ); }
Last updated on