Replies: 2 comments 1 reply
-
You should use provide/inject for this purpose https://vuejs.org/guide/components/provide-inject |
Beta Was this translation helpful? Give feedback.
1 reply
-
There's a In your case you'll do something like export const useSharedInstance = createSharedComposable(() => useMyCustomComposable("unique-key")) You can have something that "caches" shared composables based on unique-key, maybe along this lines: const composablesCache = {}
export function useSharedCustomComposable(uniqueKey) {
if (!composablesCache[uniqueKey]) {
composablesCache[uniqueKey] = createSharedComposable(() => useMyCustomComposable(uniqueKey)
}
return composablesCache[uniqueKey]()
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As per title, it would be nice to be able to share an instance of a composables between several components/pages etc...
Maybe add a unique key when instantiating the composable.
Something like this:
useMyCustomComposable.ts
index.vue
MyComponent.vue
Yes, practically a kind of store.
Beta Was this translation helpful? Give feedback.
All reactions