How can I hit my trpc endpoint in a event handler?
I am trying to hit one of my trpc end points on form submit but i keep breaking rules of hooks
7 Replies
heres what I am doing
Stack Overflow
tRPC invalid hook call in react function component
I am trying to create a new user when the user connects to the site with their wallet.
When the user clicks the button to connect, the useAccount hook will return an address of type string.
I then ...
having a different amount of hooks will break react, it tracks the order the hooks were called to identity them- https://legacy.reactjs.org/docs/hooks-rules.html#:~:text=Only%20Call%20Hooks%20at%20the%20Top%20Level&text=Instead%2C%20always%20use%20Hooks%20at,each%20time%20a%20component%20renders.
If you want to conditionally get data, call useQuery top level, and use the enabled property to control the request. Or you can use .refetch(), but this option will always cause a new request, even if your cache has data
Rules of Hooks – React
A JavaScript library for building user interfaces
i got it working
sorry shouldve said
But in your scenario, you should be using a mutation
yea
that was issue
yeah when interacting with ML model endpoints it feels like it should be using a query, but you definitely don't want background ML model runs lol