Skip to content

Commit

Permalink
fix: make sure to not crash obserable on case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Aug 2, 2024
1 parent ae2c055 commit 9429262
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib/binding/useSubscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type DependencyList, useEffect } from "react"
import { useLiveRef } from "../utils/useLiveRef"
import { makeObservable } from "../queries/client/utils/makeObservable"
import { type SubscribeSource } from "./types"
import { catchError, EMPTY } from "rxjs"

export function useSubscribe<T>(
source: SubscribeSource<T>,
Expand All @@ -10,7 +11,15 @@ export function useSubscribe<T>(
const sourceRef = useLiveRef(source)

useEffect(() => {
const sub = makeObservable(sourceRef.current).subscribe()
const sub = makeObservable(sourceRef.current)
.pipe(
catchError((error) => {
console.error(error)

return EMPTY
})
)
.subscribe()

return () => {
sub.unsubscribe()
Expand Down

0 comments on commit 9429262

Please sign in to comment.