diff options
Diffstat (limited to 'src/utils/hooks/use-toggle/use-toggle.ts')
| -rw-r--r-- | src/utils/hooks/use-toggle/use-toggle.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/utils/hooks/use-toggle/use-toggle.ts b/src/utils/hooks/use-toggle/use-toggle.ts new file mode 100644 index 0000000..c07c1e2 --- /dev/null +++ b/src/utils/hooks/use-toggle/use-toggle.ts @@ -0,0 +1,15 @@ +import { useBoolean } from '../use-boolean'; + +export type UseToggleReturn = readonly [boolean, () => void]; + +/** + * React hook to toggle boolean states. + * + * @param {boolean} [initialState] - The initial state. + * @returns {UseToggleReturn} The state and a function to switch state. + */ +export const useToggle = (initialState = false): UseToggleReturn => { + const { state, toggle } = useBoolean(initialState); + + return [state, toggle] as const; +}; |
