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: about 1 month ago
JSON representation
React hook for more convenient handling of boolean state
- Host: GitHub
- URL: https://github.com/mykolaharmash/use-boolean
- Owner: mykolaharmash
- License: mit
- Created: 2020-07-08T10:21:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-08T11:08:24.000Z (over 4 years ago)
- Last Synced: 2024-07-31T07:15:44.194Z (4 months ago)
- Topics: hook, hooks, react, react-hooks
- Language: JavaScript
- Homepage:
- Size: 57.6 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-react-hooks - `use-boolean`
- awesome-react-hooks-cn - `use-boolean`
- awesome-react-hooks - `use-boolean`
- awesome-react-hooks - `use-boolean`
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.