1
1
import React from 'react'
2
2
3
- import { useIsMounted } from './utils '
3
+ import { notifyManager } from '../core/notifyManager '
4
4
import { QueryObserver } from '../core/queryObserver'
5
5
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'
6
6
import { useQueryClient } from './QueryClientProvider'
@@ -11,10 +11,30 @@ export function useBaseQuery<TData, TError, TQueryFnData, TQueryData>(
11
11
Observer : typeof QueryObserver
12
12
) {
13
13
const queryClient = useQueryClient ( )
14
- const isMounted = useIsMounted ( )
15
14
const errorResetBoundary = useQueryErrorResetBoundary ( )
16
15
const defaultedOptions = queryClient . defaultQueryObserverOptions ( options )
17
16
17
+ // Batch calls to callbacks if not in suspense mode
18
+ if ( ! defaultedOptions . suspense ) {
19
+ if ( defaultedOptions . onError ) {
20
+ defaultedOptions . onError = notifyManager . batchCalls (
21
+ defaultedOptions . onError
22
+ )
23
+ }
24
+
25
+ if ( defaultedOptions . onSuccess ) {
26
+ defaultedOptions . onSuccess = notifyManager . batchCalls (
27
+ defaultedOptions . onSuccess
28
+ )
29
+ }
30
+
31
+ if ( defaultedOptions . onSettled ) {
32
+ defaultedOptions . onSettled = notifyManager . batchCalls (
33
+ defaultedOptions . onSettled
34
+ )
35
+ }
36
+ }
37
+
18
38
// Always set stale time when using suspense
19
39
if ( defaultedOptions . suspense && ! defaultedOptions . staleTime ) {
20
40
defaultedOptions . staleTime = 2000
@@ -38,12 +58,8 @@ export function useBaseQuery<TData, TError, TQueryFnData, TQueryData>(
38
58
// Subscribe to the observer
39
59
React . useEffect ( ( ) => {
40
60
errorResetBoundary . clearReset ( )
41
- return observer . subscribe ( result => {
42
- if ( isMounted ( ) ) {
43
- setCurrentResult ( result )
44
- }
45
- } )
46
- } , [ isMounted , observer , errorResetBoundary ] )
61
+ return observer . subscribe ( notifyManager . batchCalls ( setCurrentResult ) )
62
+ } , [ observer , errorResetBoundary ] )
47
63
48
64
// Handle suspense
49
65
if ( observer . options . suspense || observer . options . useErrorBoundary ) {
0 commit comments