@@ -82,33 +82,50 @@ export function useBaseQuery<
8282 ) ,
8383 )
8484
85- const result = observer . getOptimisticResult ( defaultedOptions )
86-
87- React . useSyncExternalStore (
88- React . useCallback (
89- ( onStoreChange ) => {
90- const unsubscribe = isRestoring
91- ? noop
92- : observer . subscribe ( notifyManager . batchCalls ( onStoreChange ) )
93-
94- // Update result to make sure we did not miss any query updates
95- // between creating the observer and subscribing to it.
96- observer . updateResult ( )
97-
98- return unsubscribe
99- } ,
100- [ observer , isRestoring ] ,
101- ) ,
102- ( ) => observer . getCurrentResult ( ) ,
103- ( ) => observer . getCurrentResult ( ) ,
104- )
85+ const [ result , setResult ] = React . useState ( ( ) => observer . getOptimisticResult ( defaultedOptions ) )
86+
87+ // console.log('result', result)
88+ React . useEffect ( ( ) => {
89+ if ( isRestoring ) {
90+ return
91+ }
92+ console . log ( 'subscribing to observer' )
93+
94+
95+ const unsubscribe = observer . subscribe (
96+ notifyManager . batchCalls ( ( newResult ) => {
97+
98+ setResult ( ( prev ) => {
99+ console . log ( 'got new result' , {
100+ prev,
101+ newResult,
102+ } )
103+ return newResult
104+
105+
106+ } )
107+ } )
108+ )
109+
110+ // Update result to make sure we did not miss any query updates
111+ // between creating the observer and subscribing to it.
112+ observer . updateResult ( )
113+
114+ return unsubscribe
115+ } , [ observer , isRestoring ] )
116+
105117
106118 React . useEffect ( ( ) => {
119+
107120 // Do not notify on updates because of changes in the options because
108121 // these changes should already be reflected in the optimistic result.
109122 observer . setOptions ( defaultedOptions , { listeners : false } )
110123 } , [ defaultedOptions , observer ] )
111124
125+
126+ React . useEffect ( ( ) => {
127+ console . log ( 'new query key' , defaultedOptions . queryHash )
128+ } , [ defaultedOptions . queryHash ] )
112129 // Handle suspense
113130 if ( shouldSuspend ( defaultedOptions , result ) ) {
114131 throw fetchOptimistic ( defaultedOptions , observer , errorResetBoundary )
0 commit comments