swr icon indicating copy to clipboard operation
swr copied to clipboard

Providing populateCache function to useSWRMutation causes onSuccess trigger callback data to be different than the returned from fetcher.

Open migonos0 opened this issue 1 year ago • 0 comments

Bug report

Description / Observed Behavior

What kind of issues did you encounter with SWR?

When using useSWRMutation, the returned trigger function would allow the developer to pass an onSuccess callback, that accepts among others, the parameter data that according to typescript should be the data returned by the fetcher, however if the developer provides a populateCache function within the useSWRMutation options, the data parameter would instead correspond to whatever is returned in the populateCache function while typescript stills hinting for the data value being whatever is returned by the fetcher.

Expected Behavior

How did you expect SWR to behave here?

Either if a populateCache function is provided or not to the useSWRMutation options, the value of the data parameter of the onSuccess callback of the returned trigger function, would remain being whatever is returned by the fetcher.

Repro Steps / Code Example

Or share your code snippet or a CodeSandbox link is also appreciated!

https://codesandbox.io/p/sandbox/gallant-browser-w8t235?file=%2Fsrc%2FApp.tsx%3A41%2C7-41%2C13

Additional Context

SWR version: 2.2.0 Add any other context about the problem here.

migonos0 avatar Jul 28 '23 00:07 migonos0