FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

useBoolean Function

10 min

Create a function called useBoolean that manages a boolean state.

The function should return an object with:

  • value: the current boolean value
  • setTrue: a function to set the value to true
  • setFalse: a function to set the value to false
  • toggle: a function to toggle the value

Example:

const { value, setTrue, setFalse, toggle } = useBoolean(false); // value is false initially setTrue(); // value becomes true toggle(); // value becomes false setFalse(); // value stays false

Code Editor

JavaScript Function

00:00
Loading...

Test Cases

No test results yet

Click "Run" to execute tests