vue-use-flag
v1.0.0
Published
A simple Vue 3 composable for making on/off states handling easier
Downloads
69
Maintainers
Readme
useFlag() Vue 3 composable
A simple composable aimed to simplify flag-like (or on/off switch) boolean variables handling
For example, you need a ref for stroging modal's opening state:
const [isModalOpened, openModal, closeModal, toggleModal] = useFlag();
// set isModalOpened to true
openModal();
// set isModalOpened to false
closeModal();
// toggle
toggleModal();
<template>
<MyModal v-if="isModalOpened"> some content </MyModal>
</template>
Usage
const [flag, on, off, toggle] = useFlag();
flag
- a ref sroging the value
on()
- sets flag value to true
off()
- sets flag value to false
toggle()
- toggles flag value between true
and false