Skip to content

Commit ce05cf3

Browse files
committed
fix(core): ensure the same observable on useObservable
1 parent c01cd43 commit ce05cf3

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

packages/core/src/bind/connectFactoryObservable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function connectFactoryObservable<A extends [], O>(
8080
return [
8181
(...input: A) => {
8282
const [source$, getValue] = getSharedObservables$(input)
83-
return useObservable(source$, getValue)
83+
return useObservable(source$, getValue, input)
8484
},
8585
(...input: A) => getSharedObservables$(input)[0],
8686
]

packages/core/src/bind/connectObservable.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import { useObservable } from "../internal/useObservable"
1818
* subscription, then the hook will leverage React Suspense while it's waiting
1919
* for the first value.
2020
*/
21+
const emptyArr: Array<any> = []
2122
export default function connectObservable<T>(observable: Observable<T>) {
2223
const sharedObservable$ = shareLatest<T>(observable, false)
2324
const getValue = reactEnhancer(sharedObservable$)
24-
const useStaticObservable = () => useObservable(sharedObservable$, getValue)
25+
const useStaticObservable = () =>
26+
useObservable(sharedObservable$, getValue, emptyArr)
2527
return [useStaticObservable, sharedObservable$] as const
2628
}

packages/core/src/internal/useObservable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Observable } from "rxjs"
66
export const useObservable = <O>(
77
source$: Observable<O>,
88
getValue: () => O,
9+
keys: Array<any>,
910
): Exclude<O, typeof SUSPENSE> => {
1011
const [state, setState] = useState(getValue)
1112
const prevStateRef = useRef<O | (() => O)>(state)
@@ -37,7 +38,7 @@ export const useObservable = <O>(
3738
t.unsubscribe()
3839

3940
return () => subscription.unsubscribe()
40-
}, [source$])
41+
}, keys)
4142

4243
return state as Exclude<O, typeof SUSPENSE>
4344
}

0 commit comments

Comments
 (0)