Skip to content
On this page

useBoolean

管理 boolean 状态的 Hook。

Demo

false
<template>
<div>
<div>{{ state }}</div>
<button @click="toggle()">toggle</button>
<button @click="setFalse()">setFalse</button>
<button @click="setTrue()">setTrue</button>
</div>
</template>

<script setup lang="ts">
import { useBoolean } from 'v3-use'
const [state, { toggle, setFalse, setTrue }] = useBoolean()
</script>

Usage

import { useBoolean } from 'v3-use'
const [state, { toggle, setFalse, setTrue }] = useBoolean()
import { useBoolean } from 'v3-use'
const [state, { toggle, setFalse, setTrue }] = useBoolean()

Reference

const [state, actions] = useBoolean(defaultValue?: boolean)
const [state, actions] = useBoolean(defaultValue?: boolean)

Type Declarations

export interface Actions {
  toggle: () => void
  setTrue: () => void
  setFalse: () => void
}
export declare function useBoolean(
  defaultValue?: boolean
): [Ref<boolean>, Actions]
export interface Actions {
  toggle: () => void
  setTrue: () => void
  setFalse: () => void
}
export declare function useBoolean(
  defaultValue?: boolean
): [Ref<boolean>, Actions]