Calling trpc mutations on client components with app router
Hello, looking for some help learning app router, any advice greatly appreciated
I'm getting an error trying to call a mutation from a client component - my aim is to collect some values with a form in a shadcn dialog (so useState required)
Setting up the mutations for create and edit:
Mutating onSubmit function:
Specific error is in the screenshot, I assume I'm just doing the client component trpc pattern wrong, but not really sure what a correct call would look like
Solution:Jump to solution
GitHub
Comparing hyhydev:main...varugasu:patch-1 · hyhydev/Modulation
Modulation Podcast Website. Contribute to hyhydev/Modulation development by creating an account on GitHub.
11 Replies
simple mutation in case it's helpful at all
Probably an error with your
~/trpc/react.tsx
. Do you mind sharing it, please?
We need to check TRPCReactProvider
And just to make sure, EpisodeForm
file contains "use client"
?it does, yeah
as far as I can tell it's unmodified from the create-t3-app setup
thanks for the help
Indeed. Same as create-t3-app. Can you share the repository? It would be easier to troubleshooting it
Will do, I'll just do a bit of GitHub wrangling to get it public
@Vargas i've put it up at https://github.com/hyhydev/Modulation/blob/main/src/app/_components/episode_form/episode_form.tsx, it's a bit messy as was porting over some page router code from a different project
here's the page router example from the other project, clicking the + icon in the top header opens this pop up
Just let me setup locally here
no worries, let me know if you need a hand
no idea if the episode card loader will work with no data so might need to comment it out in the main app router page
Just found the issue
In
src/app/layout.tsx
, Header
must be inside the TRPCReactProvider
Solution
GitHub
Comparing hyhydev:main...varugasu:patch-1 · hyhydev/Modulation
Modulation Podcast Website. Contribute to hyhydev/Modulation development by creating an account on GitHub.
thanks so much, that's a really dumb error of me lol
my pleasure