Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/mykolaharmash/use-boolean

React hook for more convenient handling of boolean state
https://github.com/mykolaharmash/use-boolean

hook hooks react react-hooks

Last synced: 3 months ago
JSON representation

React hook for more convenient handling of boolean state

Lists

README

        

# useBoolean React Hook

Convenient helpers for handling boolean state.

## Install

```
npm i use-boolean
```

## Usage

```jsx
import React from 'react'
import { useBoolean } from 'use-boolean'

function App() {
const [visible, show, hide, toggle] = useBoolean(false)

return (


{visible ?
Hello, World!
: null}

Show
Hide
Toggle


)
}
```

## [Live Example](https://codesandbox.io/s/summer-sun-44zj2)

## API

`useBoolean()` call
```ts
useBoolean(value: boolean): UseBoolean
```

`UseBoolean` return type
```ts
type UseBoolean = [boolean, SetTrue, SetFalse, Toggle, SetValue]
```

`SetTrue`, `SetFalse`, `Toggle` and `SetValue` all wrapped with `useCallback()` so you don't need to do it yourself.