Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/createSharedComposable.md
1---2category: State3related: createGlobalState4---56# createSharedComposable78Make a composable function usable with multiple Vue instances.910> [!WARNING]11> When used in a **SSR** environment, `createSharedComposable` will **automatically fallback** to a non-shared version.12> This means every call will create a fresh instance in SSR to avoid [cross-request state pollution](https://vuejs.org/guide/scaling-up/ssr.html#cross-request-state-pollution).1314## Usage1516```ts17import { createSharedComposable, useMouse } from '@vueuse/core'1819const useSharedMouse = createSharedComposable(useMouse)2021// CompA.vue22const { x, y } = useSharedMouse()2324// CompB.vue - will reuse the previous state and no new event listeners will be registered25const { x, y } = useSharedMouse()26```2728## Type Declarations2930```ts31export type SharedComposableReturn<T extends AnyFn = AnyFn> = T32/**33* Make a composable function usable with multiple Vue instances.34*35* @see https://vueuse.org/createSharedComposable36*37* @__NO_SIDE_EFFECTS__38*/39export declare function createSharedComposable<Fn extends AnyFn>(40composable: Fn,41): SharedComposableReturn<Fn>42```43