Implement a useBoolean
hook that manages a boolean state, with additional convenience utility methods.
export default function Component() {const { value, setTrue, setFalse } = useBoolean();return (<div><p>{value ? 'enabled' : 'disabled'}</p><button onClick={toggle}>Toggle</button></div>);}
initialValue: boolean
: Initial value of the boolean state. If not provided, it should default to false
.The useBoolean
hook returns an object
with the following properties.
value: boolean
: The current boolean statesetTrue: () => void
: A function to set the boolean state to true
setFalse: () => void
: A function to set the boolean state to false
Implement a useBoolean
hook that manages a boolean state, with additional convenience utility methods.
export default function Component() {const { value, setTrue, setFalse } = useBoolean();return (<div><p>{value ? 'enabled' : 'disabled'}</p><button onClick={toggle}>Toggle</button></div>);}
initialValue: boolean
: Initial value of the boolean state. If not provided, it should default to false
.The useBoolean
hook returns an object
with the following properties.
value: boolean
: The current boolean statesetTrue: () => void
: A function to set the boolean state to true
setFalse: () => void
: A function to set the boolean state to false
console.log()
statements will appear here.