createStorage ​
Creates new Storage
object.
Import ​
import { createStorage } from '@wagmi/vue'
Usage ​
import { createStorage } from '@wagmi/vue'
const storage = createStorage({ storage: localStorage })
Parameters ​
import { type CreateStorageParameters } from '@wagmi/vue'
deserialize ​
(<T>(value: string) => T) | undefined
- Function to deserialize data from storage.
- Defaults to
deserialize
.
import { createStorage, deserialize } from '@wagmi/vue'
const storage = createStorage({
deserialize,
storage: localStorage,
})
WARNING
If you use a custom deserialize
function, make sure it can handle bigint
and Map
values.
key ​
string | undefined
- Key prefix to use when persisting data.
- Detaults to
'wagmi'
.
import { createStorage } from '@wagmi/vue'
const storage = createStorage({
key: 'my-app',
storage: localStorage,
})
serialize ​
(<T>(value: T) => string) | undefined
- Function to serialize data for storage.
- Defaults to
serialize
.
import { createStorage, serialize } from '@wagmi/vue'
const storage = createStorage({
serialize,
storage: localStorage,
})
WARNING
If you use a custom serialize
function, make sure it can handle bigint
and Map
values.
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 '@wagmi/vue'
// 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 '@wagmi/vue'
Storage ​
Object responsible for persisting Wagmi State
and other data.
import { type Storage } from '@wagmi/vue'
getItem ​
getItem(key: string, defaultValue?: value | null | undefined): value | null | Promise<value | null>
import { createStorage } from '@wagmi/vue'
const storage = createStorage({ storage: localStorage })
const recentConnectorId = storage.getItem('recentConnectorId')
setItem ​
setItem(key: string, value: any): void | Promise<void>
import { createStorage } from '@wagmi/vue'
const storage = createStorage({ storage: localStorage })
storage.setItem('recentConnectorId', 'foo')
removeItem ​
removeItem(key: string): void | Promise<void>
import { createStorage } from '@wagmi/vue'
const storage = createStorage({ storage: localStorage })
storage.removeItem('recentConnectorId')