trpc giving me a hooks error?

when a button is pressed im getting a hooks error, i think because im using this function as a consequence of the button press. What is the correct way to call this?
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cje
cje2y ago
Rules of Hooks – React
A JavaScript library for building user interfaces
cornflour
cornflour2y ago
useMutation is a hook and can only be called in a function component as the error said. You need to do something like this
const YourComponent = () => {
const mutation = trpc.user.updateUserInfo.useMutation()
const saveChanges = async () => {
mutation.mutate(whatevertheParamsYouHaveHere)
}
}
const YourComponent = () => {
const mutation = trpc.user.updateUserInfo.useMutation()
const saveChanges = async () => {
mutation.mutate(whatevertheParamsYouHaveHere)
}
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Max
Max2y ago
aaah, thanks people, that makes sense ❤️
Want results from more Discord servers?
Add your server