@@ -38,10 +38,12 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
38
38
} ) ;
39
39
} ) ;
40
40
41
- const [ canResetObservable , setCanResetObservable ] = useState ( false ) ;
41
+ const canResetObservableRef = useRef ( false ) ;
42
42
useEffect ( ( ) => {
43
- return ( ) => setCanResetObservable ( true ) ;
44
- } , [ ] )
43
+ return ( ) => {
44
+ canResetObservableRef . current = true ;
45
+ } ;
46
+ } , [ ] ) ;
45
47
46
48
const ref = useRef ( { client, subscription, options } ) ;
47
49
useEffect ( ( ) => {
@@ -51,24 +53,24 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
51
53
}
52
54
53
55
if ( options ?. skip ) {
54
- if ( ! options ?. skip !== ! ref . current . options ?. skip || canResetObservable ) {
56
+ if ( ! options ?. skip !== ! ref . current . options ?. skip || canResetObservableRef . current ) {
55
57
setResult ( {
56
58
loading : false ,
57
59
data : void 0 ,
58
60
error : void 0 ,
59
61
variables : options ?. variables ,
60
62
} ) ;
61
63
setObservable ( null ) ;
62
- setCanResetObservable ( false ) ;
64
+ canResetObservableRef . current = false ;
63
65
}
64
66
} else if (
65
- shouldResubscribe !== false && (
66
- client !== ref . current . client ||
67
- subscription !== ref . current . subscription ||
68
- options ?. fetchPolicy !== ref . current . options ?. fetchPolicy ||
69
- ! options ?. skip !== ! ref . current . options ?. skip ||
70
- ! equal ( options ?. variables , ref . current . options ?. variables )
71
- ) || canResetObservable
67
+ ( shouldResubscribe !== false &&
68
+ ( client !== ref . current . client ||
69
+ subscription !== ref . current . subscription ||
70
+ options ?. fetchPolicy !== ref . current . options ?. fetchPolicy ||
71
+ ! options ?. skip !== ! ref . current . options ?. skip ||
72
+ ! equal ( options ?. variables , ref . current . options ?. variables ) ) ) ||
73
+ canResetObservableRef . current
72
74
) {
73
75
setResult ( {
74
76
loading : true ,
@@ -82,11 +84,11 @@ export function useSubscription<TData = any, TVariables = OperationVariables>(
82
84
fetchPolicy : options ?. fetchPolicy ,
83
85
context : options ?. context ,
84
86
} ) ) ;
85
- setCanResetObservable ( false ) ;
87
+ canResetObservableRef . current = false ;
86
88
}
87
89
88
90
Object . assign ( ref . current , { client, subscription, options } ) ;
89
- } , [ client , subscription , options , canResetObservable ] ) ;
91
+ } , [ client , subscription , options , canResetObservableRef . current ] ) ;
90
92
91
93
useEffect ( ( ) => {
92
94
if ( ! observable ) {
0 commit comments