Skip to main content

useAsyncStorage
hook

The useAsyncStorage hook provides functions to interact with persistent storage. It allows you to store, retrieve, and manage data that persists between app sessions.

Anchor to useAsyncStorage
useAsyncStorage()

UseAsyncStorageReturns

clear
() => Promise<void>

Clear all items from the async storage.

getAllKeys
() => Promise<string[]>

Get all keys in the async storage.

getItem
(params: ) => Promise<string>

Get an item from the async storage.

removeItem
(params: ) => Promise<void>

Remove an item from the async storage.

setItem
(params: ) => Promise<void>

Set an item in the async storage.

Was this section helpful?

Example code

import {useEffect} from 'react'

import {useAsyncStorage} from '@shopify/shop-minis-react'

export default function MyComponent() {
const {getItem, setItem, removeItem, getAllKeys, clear} = useAsyncStorage()

useEffect(() => {
async function handleStorageOperations() {
// Get an item from storage
const value = await getItem({key: 'myKey'})
console.log({value})

// Set an item in storage
await setItem({key: 'myKey', value: 'Hello, World!'})

// Remove an item from storage
await removeItem({key: 'myKey'})

// Get all keys in storage
const keys = await getAllKeys()
console.log({keys})

// Clear all items from storage
await clear()
}

handleStorageOperations()
}, [getItem, removeItem, setItem, getAllKeys, clear])
}