How to fetch data from NextJs API folder using tanstack query on button click

Hello, so I'm using tanstack query (first time ever) to fetch a NextJS API route triggered by a button click that calls the Clerk Dev backend API to delete a user. The thing is, that sometimes the API's response is successful, sometimes it is not, and since I'm new with this library I don't know what I should do or where to start. Here is my code:
3 Replies
zinter71
zinter712y ago
This is my API route. Am I missing anythong? been stuck for hours
Meierschlumpf
Meierschlumpf2y ago
As far as I can tell the issue might be, that axios.post should be called asynchronous. So maybe change that and maybe use the deleteUser.mutateAsync function (also with await) in the UserActionButtons
JulieCezar
JulieCezar2y ago
you are missing returns return res.status().json in api
Want results from more Discord servers?
Add your server