mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 09:27:50 +00:00
Automatic timed toggle
This commit is contained in:
@@ -8,6 +8,7 @@ type UseToggleReturn = [
|
|||||||
on: VoidFn;
|
on: VoidFn;
|
||||||
off: VoidFn;
|
off: VoidFn;
|
||||||
toggle: VoidFn;
|
toggle: VoidFn;
|
||||||
|
timedToggle: (timeout?: number) => void;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -26,5 +27,13 @@ export const useToggle = (initialState = false): UseToggleReturn => {
|
|||||||
setValue((prev) => (typeof isOpen === "boolean" ? isOpen : !prev));
|
setValue((prev) => (typeof isOpen === "boolean" ? isOpen : !prev));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return [value, { on, off, toggle }];
|
const timedToggle = useCallback((timeout = 2000) => {
|
||||||
|
setValue((prev) => !prev);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setValue(false);
|
||||||
|
}, timeout);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return [value, { on, off, toggle, timedToggle }];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user