Class AsyncStorage<T>

A wrapper class for AsyncStorage for strict typing and inbuilt JSON serialization.

TODO: add support for custom JSON serializer if needed

Type Parameters

  • T

Constructors

  • Create a new AsyncStorage instance. The keyPrefix is used to namespace the keys in the underlying storage layer. It's optional, but recommended to avoid key collisions.

    Type Parameters

    • T

    Parameters

    Returns AsyncStorage<T>

Methods

  • Calling this method will clear all data for the given storage layer.

    It might lead to unexpected behavior and/or data loss if other modules are using the same storage layer.

    Returns Promise<void>

  • Get the value for the given key.

    Parameters

    • key: string

    Returns Promise<null | T>

  • Remove the value for the given key.

    Parameters

    • key: string

    Returns Promise<void>

  • Set the value for the given key.

    Parameters

    • key: string
    • value: T

    Returns Promise<void>

  • Create a new AsyncStorage instance with initial data.

    Type Parameters

    • T

    Parameters

    • storage: IAsyncStorage
    • initialData: Record<string, T>
    • Optional keyPrefix: string

    Returns Promise<AsyncStorage<T>>