Files
agent-skills/skills/vueuse-functions/references/useObservable.md
Jason Woltje f5792c40be feat: Complete fleet — 94 skills across 10+ domains
Pulled ALL skills from 15 source repositories:
- anthropics/skills: 16 (docs, design, MCP, testing)
- obra/superpowers: 14 (TDD, debugging, agents, planning)
- coreyhaines31/marketingskills: 25 (marketing, CRO, SEO, growth)
- better-auth/skills: 5 (auth patterns)
- vercel-labs/agent-skills: 5 (React, design, Vercel)
- antfu/skills: 16 (Vue, Vite, Vitest, pnpm, Turborepo)
- Plus 13 individual skills from various repos

Mosaic Stack is not limited to coding — the Orchestrator and
subagents serve coding, business, design, marketing, writing,
logistics, analysis, and more.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 16:27:42 -06:00

68 lines
1.6 KiB
Markdown

---
category: '@RxJS'
---
# useObservable
Use an RxJS [`Observable`](https://rxjs.dev/guide/observable), return a `ref`, and automatically unsubscribe from it when the component is unmounted.
## Usage
<!-- TODO: import rxjs error if enable twoslash -->
```ts no-twoslash
import { useObservable } from '@vueuse/rxjs'
import { interval } from 'rxjs'
import { mapTo, scan, startWith } from 'rxjs/operators'
// setup()
const count = useObservable(
interval(1000).pipe(
mapTo(1),
startWith(0),
scan((total, next) => next + total),
),
)
```
If you want to add custom error handling to an `Observable` that might error, you can supply an optional `onError` configuration. Without this, RxJS will treat any error in the supplied `Observable` as an "unhandled error" and it will be thrown in a new call stack and reported to `window.onerror` (or `process.on('error')` if you happen to be in Node).
```ts no-twoslash
import { useObservable } from '@vueuse/rxjs'
import { interval } from 'rxjs'
import { map } from 'rxjs/operators'
// setup()
const count = useObservable(
interval(1000).pipe(
map((n) => {
if (n === 10)
throw new Error('oops')
return n + n
}),
),
{
onError: (err) => {
console.log(err.message) // "oops"
},
},
)
```
## Type Declarations
```ts
export interface UseObservableOptions<I> {
onError?: (err: any) => void
/**
* The value that should be set if the observable has not emitted.
*/
initialValue?: I | undefined
}
export declare function useObservable<H, I = undefined>(
observable: Observable<H>,
options?: UseObservableOptions<I | undefined>,
): Readonly<Ref<H | I>>
```