Skip to content

Commit 9429262

Browse files
committed
fix: make sure to not crash obserable on case of error
1 parent ae2c055 commit 9429262

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib/binding/useSubscribe.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { type DependencyList, useEffect } from "react"
22
import { useLiveRef } from "../utils/useLiveRef"
33
import { makeObservable } from "../queries/client/utils/makeObservable"
44
import { type SubscribeSource } from "./types"
5+
import { catchError, EMPTY } from "rxjs"
56

67
export function useSubscribe<T>(
78
source: SubscribeSource<T>,
@@ -10,7 +11,15 @@ export function useSubscribe<T>(
1011
const sourceRef = useLiveRef(source)
1112

1213
useEffect(() => {
13-
const sub = makeObservable(sourceRef.current).subscribe()
14+
const sub = makeObservable(sourceRef.current)
15+
.pipe(
16+
catchError((error) => {
17+
console.error(error)
18+
19+
return EMPTY
20+
})
21+
)
22+
.subscribe()
1423

1524
return () => {
1625
sub.unsubscribe()

0 commit comments

Comments
 (0)