# @gaopeng123/hooks.use-boolean

> boolean类型设置

Latest version **0.7.10-alpha.0** (published 2024-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gaopeng123/hooks.use-boolean
pnpm add @gaopeng123/hooks.use-boolean
yarn add @gaopeng123/hooks.use-boolean
bun add @gaopeng123/hooks.use-boolean
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.10-alpha.0 |
| Published | 2024-05-23 |
| First published | 2022-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ligaopeng123 |
| Maintainers | gaopeng123 |
| Keywords | boolean |

## Links

- npm: https://www.npmjs.com/package/@gaopeng123/hooks.use-boolean
- Repository: https://github.com/ligaopeng123-npm/hooks
- Homepage: https://github.com/ligaopeng123-npm/hooks#readme
- Issues: https://github.com/ligaopeng123-npm/hooks/issues
- npm.io page: https://npm.io/package/@gaopeng123/hooks.use-boolean

## Recent versions

- 0.7.10-alpha.0 (latest) — 2024-05-23
- 0.7.9 — 2024-05-23
- 0.7.8 — 2024-02-01
- 0.7.6 — 2023-09-19
- 0.7.2 — 2023-08-10
- 0.7.1 — 2023-08-02
- 0.6.3 — 2023-08-02
- 0.6.0 — 2023-05-11
- 0.5.1 — 2023-01-06
- 0.5.0 — 2022-09-29
- 0.4.4 — 2022-09-29

## README

# # useBoolean

> TODO:  bool类型定义，使用场景：窗口的打开关闭；loading状态的控制等；
>
> [在线demo](https://ligaopeng123-npm.github.io/hooks/?path=/story/example-useboolean--demo)

## 参数

`接收默认值true或者false，默认为false`

`返回值为bool和一个actions`

```tsx
type ActionsFn = () => void;
type ActionsSetFn = (val: boolean) => void;
export type Actions = {
    setTrue: ActionsFn, // 设置true
    setFalse: ActionsFn, // 设置false
    setAuto: ActionsFn, // 如果当前为true 设置为false 如果为false则为true
    setBool: ActionsSetFn // 根据传递的值设置
};
```

## Usage

```
const TestUseBoolean: React.FC<TestUseBooleanProps> = (props) => {
    const [bool, {setTrue, setFalse, setBool, setAuto}] = useBoolean(false);
    return (
        <React.Fragment>
            <h3>useBoolean</h3>
            <button onClick={() => setTrue()}>true</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button onClick={() => setFalse()}>false</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button onClick={() => setBool(true)}>setBool</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button onClick={() => setAuto()}>setAuto</button><br/>
            bool: <span>{`${bool}`}</span>
        </React.Fragment>
    )
};

export default TestUseBoolean;
```

---
_Source: https://npm.io/package/@gaopeng123/hooks.use-boolean · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
