import { useState } from "react"; import { UseToggleOptions } from "hooks"; /** * * @kind 12-State */ export const useToggle = (options?: UseToggleOptions) => { const { onValue = true, offValue = false, initialValue = false, onToggle } = options || {}; const [value, setValue] = useState(initialValue as T); const toggle = () => { const newValue = (value === onValue ? offValue : onValue) as T; setValue(newValue); onToggle?.(newValue); }; return [value, toggle, setValue] as const; };