fix shortcut

This commit is contained in:
Gabe Yuan
2023-09-08 13:53:33 +08:00
parent 850dc0e83b
commit 56350de2cf
4 changed files with 44 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react";
import { storage } from "../libs/storage";
export function useStorage(key, defaultVal = null) {
const [loading, setLoading] = useState(true);
const [data, setData] = useState(defaultVal);
const save = useCallback(
@@ -36,9 +37,16 @@ export function useStorage(key, defaultVal = null) {
useEffect(() => {
(async () => {
await reload();
try {
setLoading(true);
await reload();
} catch (err) {
//
} finally {
setLoading(false);
}
})();
}, [reload]);
return { data, save, update, remove, reload };
return { data, save, update, remove, reload, loading };
}