1- import { useEffect , useState , useRef } from "react"
1+ import { useEffect , useState } from "react"
2+ import { Observable } from "rxjs"
23import { SUSPENSE } from "../SUSPENSE"
34import { EMPTY_VALUE } from "./empty-value"
4- import { Observable } from "rxjs"
55
66export const useObservable = < O > (
77 source$ : Observable < O > ,
88 getValue : ( ) => O ,
99 keys : Array < any > ,
1010) : Exclude < O , typeof SUSPENSE > => {
1111 const [ state , setState ] = useState ( getValue )
12- const prevStateRef = useRef < O | ( ( ) => O ) > ( state )
1312
1413 useEffect ( ( ) => {
1514 let err : any = EMPTY_VALUE
@@ -27,19 +26,14 @@ export const useObservable = <O>(
2726 } , onError )
2827 if ( err !== EMPTY_VALUE ) return
2928
30- const set = ( value : O | ( ( ) => O ) ) => {
31- if ( ! Object . is ( prevStateRef . current , value ) )
32- setState ( ( prevStateRef . current = value ) )
33- }
34-
3529 const defaultValue = ( getValue as any ) . d
3630 if ( syncVal === EMPTY_VALUE ) {
37- set ( defaultValue === EMPTY_VALUE ? getValue : defaultValue )
31+ setState ( defaultValue === EMPTY_VALUE ? getValue : ( ) => defaultValue )
3832 }
3933
4034 const t = subscription
4135 subscription = source$ . subscribe ( ( value : O | typeof SUSPENSE ) => {
42- set ( value === SUSPENSE ? getValue : value )
36+ setState ( value === SUSPENSE ? getValue : ( ) => value )
4337 } , onError )
4438 t . unsubscribe ( )
4539
0 commit comments