React Hooks
createStorage

createStorage

Creates new Storage object.

Import

import { createStorage } from '@lawallet/react';

Usage

import { createStorage } from '@lawallet/react';
 
const storage = createStorage({ storage: localStorage });

Parameters

import { type CreateStorageParameters } from '@lawallet/react';

storage

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

  • Storage interface to use for persisting data.
  • Defaults to localStorage.
  • Supports synchronous and asynchronous storage methods.
import { createStorage } from '@lawallet/react';
// Using IndexedDB via https://github.com/jakearchibald/idb-keyval
import { del, get, set } from 'idb-keyval';
 
const storage = createStorage({
  storage: {
    async getItem(name) {
      return get(name);
    },
    async setItem(name, value) {
      await set(name, value);
    },
    async removeItem(name) {
      await del(name);
    },
  },
});

Return Type

import { type Storage } from '@lawallet/react';

Storage

Object responsible for persisting LaWallet Identity and other data.

import { type Storage } from '@lawallet/react';

getItem

getItem(key: string, defaultValue?: value | null | undefined): value | null | Promise<value | null>

import { createStorage } from '@lawallet/react';
 
const storage = createStorage({ storage: localStorage });
const testKey = storage.getItem('testKey');

setItem

setItem(key: string, value: any): void | Promise<void>

import { createStorage } from '@lawallet/react';
 
const storage = createStorage({ storage: localStorage });
storage.setItem('testKey', 'foo');

removeItem

removeItem(key: string): void | Promise<void>

import { createStorage } from '@lawallet/react';
 
const storage = createStorage({ storage: localStorage });
storage.removeItem('testKey');