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:
parent
337f8609c2
commit
8ef10d5273
5 changed files with 104 additions and 43 deletions
19
src/utils/hooks/usePersistedState.ts
Normal file
19
src/utils/hooks/usePersistedState.ts
Normal 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];
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue