create-unique-shared-composable
v1.0.0
Published
![GitHub License](https://img.shields.io/github/license/GloryWong/createUniqueSharedComposable) ![GitHub commit activity](https://img.shields.io/github/commit-activity/w/GloryWong/createUniqueSharedComposable) ![GitHub Actions Workflow Status](https://img
Downloads
3
Maintainers
Readme
createUniqueSharedComposable
Create Vue3 unique shared composables based on keys.
This is similar to the createSharedComposable and createGlobalStates of vueuse, however, uses keys to create independent shared states.
Install
Using pnpm:
pnpm add create-unique-shared-composable
Using yarn:
yarn add create-unique-shared-composable
Using npm:
npm install create-unique-shared-composable
Usage
import { createUniqueSharedComposable } from 'create-unique-shared-composable'
const useFoo = createUniqueSharedComposable((_) => {
const counter = ref(0)
const doubled = computed(() => counter.value * 2)
return {
counter,
doubled
}
})
const { counter, doubled } = useFoo('key')
const { counter: counter1, doubled: doubled1 } = useFoo('key')
const { counter: counter2, doubled: doubled2 } = useFoo('key2')
counter.value++
console.log(counter.value) // 1
console.log(doubled.value) // 2
console.log(counter1.value) // 1
console.log(doubled1.value) // 2
console.log(counter1.value) // 0
console.log(doubled1.value) // 0
Authors
👤 GloryWong
- Website: https://glorywong.com
- GitHub: @GloryWong
Show Your Support
Give a ⭐️ if this project helped you!