You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The hono stacks page showing RPC react example with posts and gets is really useful showing how hono and RPC with tanstack query can be used for frontend and backend.
However to get the example working I had to change the way the mutation worked by adding mutationFN. Could be worth updating the page?
Another thing worth noting, is that with the example in the docs, the onError callback doesn't seem to be triggered when the API throws.
Even when there is a 400 or 500 in the API, the onSuccess is still called. The onle way I was able to make it work, was by throwing inside the mutationFn, like so:
constmutation=useMutation<InferResponseType<typeof$post>,Error,InferRequestType<typeof$post>['form']>({// Mutation functionmutationFn: async(todo)=>{constres=await$post({form: todo,});// Only by throwing here, the onError is calledif(!res.ok)thrownewError()returnawaitres.json()},// Success handleronSuccess: async()=>{queryClient.invalidateQueries({queryKey: ['todos']})},// Error handleronError: (error: Error)=>{console.error(error)},})
@usualoma could you share some insights on why this is?
The hono stacks page showing RPC react example with posts and gets is really useful showing how hono and RPC with tanstack query can be used for frontend and backend.
However to get the example working I had to change the way the mutation worked by adding mutationFN. Could be worth updating the page?
Current code example
Changed to
The text was updated successfully, but these errors were encountered: