Skip to content
On this page

createSharedComposable

Category
Export Size
287 B
Last Changed
last year
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()
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 (...args: any[]) => any
>(composable: Fn): Fn
/**
 * Make a composable function usable with multiple Vue instances.
 *
 * @see https://vueuse.org/createSharedComposable
 */
export declare function createSharedComposable<
  Fn extends (...args: any[]) => any
>(composable: Fn): Fn

Source

SourceDocs

Contributors

Anthony Fu
Egor Kotlyarov

Changelog

No recent changes

Released under the MIT License.