In the documentation linked below, the backend code returns data from the mutation call. Attached code for reference:
return {
user: {
name: opts.input.name,
role: 'ADMIN',
},
However, even when the mutation is invoked on the client side, the data is not being retrieved. Attached code for reference:
export function MyComponent() {
// This can either be a tuple ['login'] or string 'login'
const mutation = trpc.login.useMutation();
const handleLogin = () => {
const name = 'John Doe';
mutation.mutate({ name });
};
I encountered difficulty fetching data from the backend code during the mutation. Therefore, I would like to add an example on the client side to address this issue.
https://trpc.io/docs/client/react/useMutation
There was no section in the documentation that explained the process of retrieving data during a mutation call on the client side. I attempted to implement this on my own but encountered issues with the asynchronous nature of the operation. Specifically, the data was not being resolved before the variable was being set. Therefore, when attempting to assign the variable from the returned data of the mutation call, it appeared as undefined.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too