Don't re-read storage on useFavorites (#4639)

This commit is contained in:
Jaco Greeff 2021-02-09 15:38:13 +01:00 committed by GitHub
parent f14156a3c0
commit a72f9be38c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,7 @@ import { useCacheKey } from './useCacheKey';
// hook for favorites with local storage
export function useFavorites (storageKeyBase: string): [string[], (address: string) => void] {
const [getCache, setCache] = useCacheKey<string[]>(storageKeyBase);
const [favorites, setFavorites] = useState<string[]>(getCache() || []);
const [favorites, setFavorites] = useState<string[]>(() => getCache() || []);
const toggleFavorite = useCallback(
(address: string): void => setFavorites(