Vue hook that tracks state of a boolean
useBoolean
is an alias foruseToggle
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>
)
}
})
function useToggle(
initialValue: boolean = false
): [Ref<boolean>, (value?: unknown) => void]