> For the complete documentation index, see [llms.txt](https://yanzhandong868.gitbook.io/v3hooks/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yanzhandong868.gitbook.io/v3hooks/state/useboolean.md).

# useBoolean

## 使用

```
<template>
    <div>
      <p>{{ useBooleanState }}</p>
      <button @click="useBooleanToggle">toggle</button>
      <button @click="setTrue">setTrue</button>
      <button @click="setFalse">setFalse</button>
    </div>
</template>

<script lang="ts">

import { ref } from 'vue';
import { useBoolean } from 'v3hooks';


export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },

  setup() {
    //useToggle 测试
    const [ useBooleanState,{ toggle: useBooleanToggle, setTrue, setFalse}] = useBoolean();


    return {
      useBooleanState,
      useBooleanToggle,
      setTrue,
      setFalse
    }
  }
}
</script>
```

useBoolean默认切换布尔值状态，也可以接收一个参数作为新的值。

## Api

### Params

|      参数      |      说明      |    类型   |  默认值  |
| :----------: | :----------: | :-----: | :---: |
| defaultValue | 可选项，传入默认的状态值 | boolean | false |

### Result

|    参数   |  说明  |       类型      |
| :-----: | :--: | :-----------: |
|  state  |  状态值 | Ref\<boolean> |
| actions | 操作集合 |    Actions    |

### Actions

|    参数    |             说明            |             类型            |
| :------: | :-----------------------: | :-----------------------: |
|  toggle  | 触发状态更改的函数,可以接受一个可选参数修改状态值 | (value?: boolean) => void |
|  setTrue |        设置状态值为 true        |         () => void        |
| setFalse |        设置状态值为 false       |         () => void        |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://yanzhandong868.gitbook.io/v3hooks/state/useboolean.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
