type of a TRPC mutation

What is the type of a TRPC mutation if I want to pass it into a component
export default function MyComponent({ myMutation} : {myMutation: ???} {
// mutating things...
}
export default function MyComponent({ myMutation} : {myMutation: ???} {
// mutating things...
}
4 Replies
whatplan
whatplan16mo ago
Just call useMutation in that component? Why do you need to pass it as a prop?
Tom
Tom16mo ago
in general. i agree with @whatplan but to answer the question:
type MutationType = ReturnType<typeof trpc.users.generateApiKey.useMutation>
type MutationType = ReturnType<typeof trpc.users.generateApiKey.useMutation>
isaac_way
isaac_way16mo ago
sometimes it can make sense to have a reusable component that accepts any mutation as a prop, in which case you can use @tanstack/react-querys UseMutationResult type
danmrkw
danmrkw16mo ago
Thanks for replying. I use the same mutation in the parent component as well as in the child. Seems inefficient to repeat oneself. typescript seems to accept that - thank you 🙂
Want results from more Discord servers?
Add your server
More Posts