mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-18 14:23:44 +02:00
Support filtering to own/all servers if user is an admin
This commit is contained in:
23
resources/scripts/plugins/usePersistedState.ts
Normal file
23
resources/scripts/plugins/usePersistedState.ts
Normal 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 ];
|
||||
}
|
||||
Reference in New Issue
Block a user