The useBoolean Hook

The useBoolean Hook is used to deal with toggling boolean values (true/false), and provides functions to set the value to true/false, and a toggle function to toggle the value.

The Hook returns an object with the following:

  • value: The current value of the boolean
  • toggle: A function to toggle the current value (sets true if currently false, and false if currently true)
  • setTrue: Sets the current value to true
  • setFalse: Sets the current value to false

The Boolean Hook works as follows:

  1. First, we import the useBoolean Hook from react-hookedup:
import React from 'react'import { useBoolean } from 'react-hookedup'
  1. Then, we define our component and the Boolean Hook, which returns an object with the toggle function and value ...

Get Learn React Hooks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.