In v4, I could do:

const result = await queryClient.executeMutation({
mutationFn: () => fetch('/api/data', {
method: 'POST',
body: JSON.stringify(newData),
headers: { 'Content-Type': 'application/json' }
}).then(res => res.json()),
// Optional callbacks
onSuccess: (data) => { console.log('Success:', data); },
onError: (error) => { console.error('Error:', error); }
});

That was removed in v5, what is the closest way to do the same in v5?

ChatGPT suggests this monstrosity, but it seems wrong, is this really the way to do it in v5?

function createImperativeMutation(mutationFn) { const observer = new MutationObserver(queryClient, { mutationFn }); return { mutate: (variables) => observer.mutate(variables), mutateAsync: (variables) => observer.mutate(variables) }; } // Usage co...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help