feat(ui): added new auth guard with react-query and axios

This commit is contained in:
akhilmhdh
2023-01-26 00:14:01 +05:30
parent a6f480d3f8
commit a6387e7552
16 changed files with 234 additions and 30 deletions
+30
View File
@@ -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 }];
};