Vaultrice React SDK - v1.1.0
    Preparing search index...

    Function useNonLocalObject

    • React hook for managing an object stored in NonLocalStorage with atomic helpers.

      This hook exposes a reactive object value plus an actions object that provides atomic operations implemented by the underlying @vaultrice/sdk NonLocalStorage:

      • merge: shallowly merges properties into the stored object (creates object if missing)
      • setIn: sets a nested value using a dot-path (creates parents as needed)
      • setObject: replaces the whole object

      The hook keeps local state in sync with remote updates (unless options.bind === false), returns any operation errors and exposes an isLoading flag for initial load / async ops.

      Type Parameters

      • T extends Record<string, ValueType> = Record<string, ValueType>

        Shape of the stored object (defaults to Record<string, ValueType>)

      Parameters

      • id: string

        NonLocalStorage instance id (room/store id)

      • key: string

        Key identifying the stored object

      • options: UseNonLocalStorageOptions

        Hook options (credentials, instanceOptions, bind)

      Returns UseNonLocalObjectReturn<T>

      A tuple:

      • object: T — current object value (defaults to {} when missing)
      • actions: { merge(objectToMerge: Partial, opts?): Promise, setIn(path: string, val: any, opts?): Promise, setObject(obj: T, opts?): Promise }
      • error: any — error encountered during operations
      • isLoading: boolean — true while initial load or an async get/set is in progress

      Example: const [user, { merge, setIn, setObject }, error, isLoading] = useNonLocalObject<{ name?:string, profile?:{ avatar?:string } }>('room1', 'user', { credentials: {...} })

      // shallow merge await merge({ name: 'Alice' })

      // set nested await setIn('profile.avatar', 'avatar.jpg')

      // replace whole object await setObject({ name: 'Alice', profile: { avatar: 'avatar.jpg' } })