Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 824 Bytes

doc.md

File metadata and controls

38 lines (31 loc) · 824 Bytes

useBoolean

Vue hook that tracks state of a boolean

useBoolean is an alias for useToggle

Usage

import { createComponent } from '@vue/composition-api'
import { useBoolean } from 'vuses'

const Demo = createComponent({
  setup() {
    const [state, toggle] = useBoolean()
    return { state, toggle }
  },
  render() {
    const { state, toggle } = this
    return (
      <div>
        <div>{state ? 'ON' : 'OFF'}</div>
        <button onClick={toggle}>Toggle</button>
        <button onClick={() => toggle(true)}>set true</button>
        <button onClick={() => toggle(false)}>set false</button>
      </div>
    )
  }
})

Reference

function useBoolean(
  initialValue: boolean = false
): [Ref<boolean>, (value?: unknown) => void]