import { setStorageSync, getStorageSync, removeStorageSync } from "@tarojs/taro";
import { useCallback, useState } from "react";
export function useStorage() {
const [historyStorage, setStorage] = useState([])
const useSetStorage = useCallback((value) => {
const historyItem = Array.from(new Set(historyStorage.concat([value])))
setStorage(historyItem)
setStorageSync('history', historyItem)
}, [historyStorage])
const useGetStorage = useCallback(() => {
setStorage(getStorageSync('history') || [])
}, [])
const useRemoveStorage = useCallback(() => {
setStorage([])
removeStorageSync('history')
}, [])
return {
historyStorage,
useSetStorage,
useGetStorage,
useRemoveStorage
}
}
Taro 本地储存storage hook 封装
最新推荐文章于 2024-08-16 08:46:29 发布
关键词由CSDN通过智能技术生成