fn
createSharedComposable
v0.0.15testeddemoPromotes a composable to a shared one: every call reuses the same instance backed by a single effect scope. The scope is created lazily on the first consumer and is ref-counted, so it is disposed only when the last consumer's scope unmounts. State is recreated on the next call after a full dispose.
Example
ts
const useSharedMouse = createSharedComposable(useMouse);
// Both components share a single set of listeners and reactive state.
const { x, y } = useSharedMouse();Demo
Loading demo…
Signature
ts
export function createSharedComposable<Fn extends AnyFunction>(
composable: Fn,
): CreateSharedComposableReturn<Fn>{ ... }Type Parameters
Fnextends AnyFunctionParameters
| Parameter | Type | Description |
|---|---|---|
composable | Fn | The composable to share across consumers. |
Returns
FnA shared variant of the composable with the same signature.