query
query copied to clipboard
codemod: `remove-overloads` does not handle `useMutation`
Describe the bug
According to the update guide, the following replacement needs to be performed on useMutation
:
- useMutation(fn, options)
+ useMutation({ mutationFn, ...options })
Unfortunately it turns out the remove-overloads
codemod does not perform this replacement.
Your minimal, reproducible example
https://stackblitz.com/github/gillkyle/query-v5-codemod?file=src%2Fhooks.ts
Steps to reproduce
- Open the sandbox, and wait for
npm install
to finish - Run the codemod via the version in
node_modules
:
npx jscodeshift ./src/ \
--extensions=ts,tsx \
--parser=tsx \
--transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.js
Expected behavior
I would have expected the following lines
return useMutation(({ groupId }: { groupId: string }) => {
return fetch(`/api/groups/${groupId}`, {
method: "DELETE",
});
});
to become
return useMutation({
mutationFn: ({ groupId }: { groupId: string }) => {
return fetch(`/api/groups/${groupId}`, {
method: 'DELETE',
});
},
});
But the lines remain untouched.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: linux
- Browser: Chrome
- Version: 5.14.0
Tanstack Query adapter
None
TanStack Query version
5.14.0
TypeScript version
No response
Additional context
Follow up to issue https://github.com/TanStack/query/issues/6204
@balazsmatepetro can you have a look here please?
@balazsmatepetro can you have a look here please?
Sure!
Any update on this @balazsmatepetro @TkDodo? facing issue while migrating to v5.
@balazsmatepetro are you working on this ?
@balazsmatepetro @TkDodo
@nayan-c247 if this is important to you, please consider contributing rather than tagging people. Thanks.
Hi @nayan-c247! Sorry for the late response, recently I didn't have time to work on codemods. I will check it this week and will get back to you! Thank you for your understanding. 🙏
Hi @nayan-c247! It seems I found the root cause of the issue, but unfortunately, I need some more time to implement it. 😬 I will get back to you later this week!
I opened https://github.com/TanStack/query/pull/7187 to propose a fix. @balazsmatepetro any comments are welcome, happy to change anything if needed :slightly_smiling_face:
Great job @slax57! I approved your PR. 🎉