1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

added fluid flow toggle

This commit is contained in:
Fedor Katurov 2021-06-23 16:37:47 +07:00
parent 337f8609c2
commit 8ef10d5273
5 changed files with 104 additions and 43 deletions

View file

@ -0,0 +1,19 @@
import { useEffect, useMemo, useState } from 'react';
export const usePersistedState = (key: string, initial: string): [string, (val: string) => any] => {
const stored = useMemo(() => {
try {
return localStorage.getItem(`vault_${key}`) || initial;
} catch (e) {
return initial;
}
}, [key]);
const [val, setVal] = useState<string>(stored);
useEffect(() => {
localStorage.setItem(`vault_${key}`, val);
}, [val]);
return [val, setVal];
};