Skip to content

createSharedComposable ​

Category
Export Size
213 B
Last Changed
3 minutes ago
Related

Make a composable function usable with multiple Vue instances.

Usage ​

ts
import { createSharedComposable, useMouse } from '@vueuse/core'

const useSharedMouse = createSharedComposable(useMouse)

// CompA.vue
const { x, y } = useSharedMouse()

// CompB.vue - will reuse the previous state and no new event listeners will be registered
const { x, y } = useSharedMouse()

Type Declarations ​

typescript
/**
 * Make a composable function usable with multiple Vue instances.
 *
 * @see https://vueuse.org/createSharedComposable
 */
export declare function createSharedComposable<Fn extends AnyFn>(
  composable: Fn,
): Fn

Source ​

Source • Docs

Contributors ​

Anthony Fu
Anthony Fu
XinXiao
童欧巴
Egor Kotlyarov

Changelog ​

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v11.0.2 on 8/24/2024
a2441 - fix: handle the case where the return value of composable function is empty (#4151)

Released under the MIT License.