Skip to content

createSharedComposable

Category
Export Size
232 B
Last Changed
3 weeks 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

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

Source

SourceDocs

Contributors

Anthony Fu
SerKo
Robin
Anthony Fu
XinXiao
童欧巴
Egor Kotlyarov

Changelog

v13.6.0 on
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v11.0.2 on
a2441 - fix: handle the case where the return value of composable function is empty (#4151)

Released under the MIT License.

FREE WEEKEND
48 Hours of Unlimited Official Vue.js Certification Training
Reserve Your Spot
23-24 August