mirror of
https://github.com/hanzo-io/chat.git
synced 2026-10-30 18:57:58 +00:00
19 lines
501 B
TypeScript
19 lines
501 B
TypeScript
import { useCallback, useState } from "react";
|
|
|
|
/**
|
|
* Simple hook to manage boolean (on - off) states
|
|
* @param initialState
|
|
* @returns
|
|
*/
|
|
export function useBoolean(initialState: boolean = false) {
|
|
|
|
const [value, setValue] = useState(initialState);
|
|
|
|
const on = useCallback(() => setValue(true), []);
|
|
|
|
const off = useCallback(() => setValue(false), []);
|
|
|
|
const toggle = useCallback(() => setValue(value => !value), []);
|
|
|
|
return [value, { on, off, toggle }, setValue] as const;
|
|
} |