@@ -184,12 +184,10 @@ export const useCreate = <
184184 . then ( ( { data } ) => data ) ;
185185 } ,
186186 ...mutationOptions ,
187- onMutate : async (
188- variables : Partial < UseCreateMutateParams < RecordType > >
189- ) => {
187+ onMutate : async ( ...args ) => {
190188 if ( mutationOptions . onMutate ) {
191189 const userContext =
192- ( await mutationOptions . onMutate ( variables ) ) || { } ;
190+ ( await mutationOptions . onMutate ( ... args ) ) || { } ;
193191 return {
194192 snapshot : snapshot . current ,
195193 // @ts -ignore
@@ -200,27 +198,27 @@ export const useCreate = <
200198 return { snapshot : snapshot . current } ;
201199 }
202200 } ,
203- onError : ( error , variables , context : { snapshot : Snapshot } ) => {
201+ onError : ( ... args ) => {
204202 if ( mode . current === 'optimistic' || mode . current === 'undoable' ) {
203+ const [ , , onMutateResult ] = args ;
205204 // If the mutation fails, use the context returned from onMutate to rollback
206- context . snapshot . forEach ( ( [ key , value ] ) => {
207- queryClient . setQueryData ( key , value ) ;
208- } ) ;
205+ ( onMutateResult as { snapshot : Snapshot } ) . snapshot . forEach (
206+ ( [ key , value ] ) => {
207+ queryClient . setQueryData ( key , value ) ;
208+ }
209+ ) ;
209210 }
210211 if ( callTimeOnError . current ) {
211- return callTimeOnError . current ( error , variables , context ) ;
212+ return callTimeOnError . current ( ... args ) ;
212213 }
213214 if ( mutationOptions . onError ) {
214- return mutationOptions . onError ( error , variables , context ) ;
215+ return mutationOptions . onError ( ... args ) ;
215216 }
216217 // call-time error callback is executed by react-query
217218 } ,
218- onSuccess : (
219- data : ResultRecordType ,
220- variables : Partial < UseCreateMutateParams < RecordType > > = { } ,
221- context : unknown
222- ) => {
219+ onSuccess : ( ...args ) => {
223220 if ( mode . current === 'pessimistic' ) {
221+ const [ data , variables ] = args ;
224222 const { resource : callTimeResource = resource } = variables ;
225223 queryClient . setQueryData (
226224 [ callTimeResource , 'getOne' , { id : String ( data . id ) } ] ,
@@ -243,38 +241,26 @@ export const useCreate = <
243241 mutationOptions . onSuccess &&
244242 ! hasCallTimeOnSuccess . current
245243 ) {
246- mutationOptions . onSuccess ( data , variables , context ) ;
244+ mutationOptions . onSuccess ( ... args ) ;
247245 }
248246 }
249247 } ,
250- onSettled : (
251- data ,
252- error ,
253- variables ,
254- context : { snapshot : Snapshot }
255- ) => {
248+ onSettled : ( ...args ) => {
256249 if ( mode . current === 'optimistic' || mode . current === 'undoable' ) {
250+ const [ , , , onMutateResult ] = args ;
257251 // Always refetch after error or success:
258- context . snapshot . forEach ( ( [ queryKey ] ) => {
259- queryClient . invalidateQueries ( { queryKey } ) ;
260- } ) ;
252+ ( onMutateResult as { snapshot : Snapshot } ) . snapshot . forEach (
253+ ( [ queryKey ] ) => {
254+ queryClient . invalidateQueries ( { queryKey } ) ;
255+ }
256+ ) ;
261257 }
262258
263259 if ( callTimeOnSettled . current ) {
264- return callTimeOnSettled . current (
265- data ,
266- error ,
267- variables ,
268- context
269- ) ;
260+ return callTimeOnSettled . current ( ...args ) ;
270261 }
271262 if ( mutationOptions . onSettled ) {
272- return mutationOptions . onSettled (
273- data ,
274- error ,
275- variables ,
276- context
277- ) ;
263+ return mutationOptions . onSettled ( ...args ) ;
278264 }
279265 } ,
280266 } ) ;
@@ -409,7 +395,12 @@ export const useCreate = <
409395 onSuccess (
410396 callTimeData as unknown as ResultRecordType ,
411397 { resource : callTimeResource , ...callTimeParams } ,
412- { snapshot : snapshot . current }
398+ { snapshot : snapshot . current } ,
399+ {
400+ client : queryClient ,
401+ mutationKey : [ resource , 'create' , params ] ,
402+ meta : mutationOptions . meta ,
403+ }
413404 ) ;
414405 } else if (
415406 mutationOptions . onSuccess &&
@@ -418,7 +409,12 @@ export const useCreate = <
418409 mutationOptions . onSuccess (
419410 callTimeData as unknown as ResultRecordType ,
420411 { resource : callTimeResource , ...callTimeParams } ,
421- { snapshot : snapshot . current }
412+ { snapshot : snapshot . current } ,
413+ {
414+ client : queryClient ,
415+ mutationKey : [ resource , 'create' , params ] ,
416+ meta : mutationOptions . meta ,
417+ }
422418 ) ;
423419 }
424420 } , 0 ) ;
0 commit comments