Skip to content

Latest commit

 

History

History
38 lines (31 loc) · 822 Bytes

doc.md

File metadata and controls

38 lines (31 loc) · 822 Bytes

useToggle

Vue hook that tracks state of a boolean

useBoolean is an alias for useToggle

Usage

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

const Demo = createComponent({
  setup() {
    const [state, toggle] = useToggle(false)
    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 ON</button>
        <button onClick={() => toggle(false)}>set OFF</button>
      </div>
    )
  }
})

Reference

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