⬅️ Back to Table of Contents
📄 useBool.ts
📊 Analysis Summary
Metric |
Count |
🔧 Functions |
1 |
📦 Imports |
4 |
📚 Table of Contents
🛠️ File Location:
📂 packages/website/src/hooks/useBool.ts
📦 Imports
Name |
Source |
Dispatch |
react |
SetStateAction |
react |
useCallback |
react |
useState |
react |
Functions
useBool(initialState: boolean | (() => boolean)): [boolean, () => void, Dispatch<SetStateAction<boolean>>]
Code
export function useBool(
initialState: boolean | (() => boolean),
): [boolean, () => void, Dispatch<SetStateAction<boolean>>] {
const [value, setValue] = useState(initialState);
const toggle = useCallback(
(): void => setValue(currentValue => !currentValue),
[],
);
return [value, toggle, setValue];
}
- Parameters:
initialState: boolean | (() => boolean)
- Return Type:
[boolean, () => void, Dispatch<SetStateAction<boolean>>]
- Calls:
useState (from react)
useCallback (from react)
setValue