Hiyve Components - v1.0.0
    Preparing search index...

    Function createAsyncStorageAdapter

    • Creates an AsyncStorage-backed adapter with a synchronous in-memory cache.

      Parameters

      • asyncStorage: {
            getItem(key: string): Promise<string | null>;
            setItem(key: string, value: string): Promise<void>;
        }

        An object matching the @react-native-async-storage/async-storage API (must have getItem and setItem methods).

      Returns StorageAdapter & { init(keys: string[]): Promise<void> }

      A StorageAdapter with an additional init() method for cache hydration.

      Reads are synchronous (from the in-memory cache), and writes update the cache immediately then persist to AsyncStorage asynchronously (fire-and-forget). Call init() once at app startup to hydrate the cache from AsyncStorage before creating the store.

      Using with @react-native-async-storage/async-storage:

      import AsyncStorage from '@react-native-async-storage/async-storage';
      import { createAsyncStorageAdapter, HiyveStoreRN } from '@hiyve/rn-core';

      const storage = createAsyncStorageAdapter(AsyncStorage);

      // Hydrate the cache before creating the store
      await storage.init(['hiyve:audioDevice', 'hiyve:videoDevice']);

      const store = new HiyveStoreRN(client, { storage });