Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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: about 1 month ago
JSON representation

React hook for more convenient handling of boolean state

Awesome Lists containing this project

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.