mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
fix(core): prevent bind-hook from returning a wrong intermediate value afer Suspense
This commit is contained in:
parent
ef9cda1e44
commit
f24baf4deb
@ -16,14 +16,16 @@ export const useObservable = <O>(
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const { gV }: { gV: any } = source$
|
||||
const suspend = () => {
|
||||
setState(() => [source$.gV(), source$])
|
||||
}
|
||||
|
||||
let isEmtpy = true
|
||||
let isEmpty = true
|
||||
const subscription = source$.aH(
|
||||
(value: O | typeof SUSPENSE) => {
|
||||
isEmtpy = false
|
||||
isEmpty = false
|
||||
if (value === SUSPENSE) {
|
||||
setState(gV)
|
||||
suspend()
|
||||
} else {
|
||||
if (!Object.is(prevStateRef.current, value)) {
|
||||
setState([(prevStateRef.current = value), source$])
|
||||
@ -31,13 +33,13 @@ export const useObservable = <O>(
|
||||
}
|
||||
},
|
||||
(error: any) => {
|
||||
isEmtpy = false
|
||||
isEmpty = false
|
||||
setState(() => {
|
||||
throw error
|
||||
})
|
||||
},
|
||||
)
|
||||
if (isEmtpy) setState(gV)
|
||||
if (isEmpty) suspend()
|
||||
|
||||
return () => {
|
||||
subscription.unsubscribe()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user