Support filtering to own/all servers if user is an admin

This commit is contained in:
Dane Everitt 2020-04-25 17:52:32 -07:00
parent 67c6be9f6f
commit f45c03a449
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 86 additions and 19 deletions

View file

@ -0,0 +1,23 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
export function usePersistedState<S = undefined> (key: string, defaultValue: S): [S | undefined, Dispatch<SetStateAction<S | undefined>>] {
const [state, setState] = useState(
() => {
try {
const item = localStorage.getItem(key);
return JSON.parse(item || (String(defaultValue)));
} catch (e) {
console.warn('Failed to retrieve persisted value from store.', e);
return defaultValue;
}
}
);
useEffect(() => {
localStorage.setItem(key, JSON.stringify(state))
}, [key, state]);
return [ state, setState ];
}