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
whatplan2y ago
Just call useMutation in that component? Why do you need to pass it as a prop?
Tom
Tom2y 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_way2y 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
danmrkwOP2y 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