📄 useBool¶
📊 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>>]¶
Parameters:
initialStateboolean | (() => boolean)
Returns: [boolean, () => void, Dispatch<SetStateAction<boolean>>]
Calls:
useState (from react)useCallback (from react)setValue
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];
}
Generated by Syntax Scribe