vue-hooks-plus
Version:
Vue hooks library
25 lines (24 loc) • 611 B
JavaScript
import { ref, readonly, markRaw } from "vue";
function useSet(initialValue) {
const getInitValue = () => {
return initialValue === void 0 ? /* @__PURE__ */ new Set() : new Set(initialValue);
};
const state = ref(getInitValue());
const actions = {
add: (value) => {
state.value.add(value);
},
remove: (value) => {
state.value.delete(value);
},
has: (value) => state.value.has(value),
clear: () => state.value.clear(),
reset: () => {
state.value = getInitValue();
}
};
return [readonly(state), markRaw(actions)];
}
export {
useSet as default
};