mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 14:27:23 +00:00
feat(ui): added new auth guard with react-query and axios
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
type VoidFn = () => void;
|
||||
|
||||
type UseToggleReturn = [
|
||||
boolean,
|
||||
{
|
||||
on: VoidFn;
|
||||
off: VoidFn;
|
||||
toggle: VoidFn;
|
||||
}
|
||||
];
|
||||
|
||||
export const useToggle = (initialState = false): UseToggleReturn => {
|
||||
const [value, setValue] = useState(initialState);
|
||||
|
||||
const on = useCallback(() => {
|
||||
setValue(true);
|
||||
}, []);
|
||||
|
||||
const off = useCallback(() => {
|
||||
setValue(false);
|
||||
}, []);
|
||||
|
||||
const toggle = useCallback((isOpen?: boolean) => {
|
||||
setValue((prev) => (typeof isOpen === 'boolean' ? isOpen : !prev));
|
||||
}, []);
|
||||
|
||||
return [value, { on, off, toggle }];
|
||||
};
|
||||
Reference in New Issue
Block a user