UseBoolean
import { useMemo, useState } from 'react';
interface Actions {
setTrue: () => void,
setFalse: () => void,
setToggle: () => void,
}
const useBoolean = (defaultValue: boolean = false): [boolean, Actions]=> {
const [value, setValue] = useState<boolean>(defaultValue);
const actions = useMemo(() => {
const setTrue = () => setValue(true);
const setFalse = () => setValue(false);
const setToggle = () => setValue(!value);
return { setTrue, setFalse, setToggle };
}, [value]);
return [
value,
actions
];
};
export default useBoolean;