[Glitch] Adds useToggle hook

Port dff66fe890 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Echo authored and Claire committed 2026-07-06 19:53:46 +02:00
1 parent b2a3af7610
commit 7ccd447c2b
2 files changed
+19 -5

No files matched your search

@@ -0,0 +1,16 @@
import { useCallback, useState } from 'react';
export function useToggle(initialValue: boolean | (() => boolean) = false) {
const [value, setValue] = useState(initialValue);
const onTrue = useCallback(() => {
setValue(true);
}, []);
const onFalse = useCallback(() => {
setValue(false);
}, []);
const onToggle = useCallback(() => {
setValue((prevValue) => !prevValue);
}, []);
return [value, { setValue, onTrue, onFalse, onToggle }] as const;
}