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

    Function useNonLocalArray

    • React hook for managing an array in NonLocalStorage with atomic operations.

      Provides reactive access to an array stored under key on a NonLocalStorage instance. The hook returns the current array (defaulting to []), an actions object with atomic helpers (push, setArray), an error value and a loading flag.

      Features:

      • Atomic server-side push to append elements safely across concurrent clients.
      • Convenience setter to replace the whole array.
      • Automatic subscription to remote updates (unless options.bind === false).
      • Error handling and isLoading state for async operations.

      Type Parameters

      • T extends ValueType

        Element type stored in the array.

      Parameters

      • id: string

        NonLocalStorage instance id (room/store id).

      • key: string

        Key identifying the array value.

      • options: UseNonLocalStorageOptions

        Hook options (credentials, instanceOptions, bind).

      Returns UseNonLocalArrayReturn<T>

      A tuple:

      • array: T[] — current array value (or [] when missing)
      • actions: { push(element: T, opts?: any): Promise, setArray(arr: T[], opts?: any): Promise }
      • error: any — any error that occurred during operations
      • isLoading: boolean — true while initial load or an async get/set is in progress

      Example: const [items, { push, setArray }, error, isLoading] = useNonLocalArray<{ id:number, text:string }>('room1', 'todos', { credentials: {...} })

      await push({ id: 1, text: 'Buy milk' }) await setArray([{ id: 1, text: 'Buy milk' }])