setMutationDefaults for optimistic updates
I have a
preferences
router, with a get
query and a set
mutation. I had optimistic updates set up in the onSuccess of the useMutation hook, wherever I used it, like this:
Now that I'm adding more and more instances where I need to use the set
endpoint, I don't want to copy paste the onSuccess
for optimistic updates. There is the setMutationDefaults
function of query client that would be ideal for this but it isn't working.
Is this not working in tRPC wrapper because it's not setting the mutationKey
or am I doing something wrong? Like I could make a wrapper hook for this mutation but using these defaults seems to me like much cleaner solution.H
Haaxor1689โข367d ago
Hmm I found this closed issue https://github.com/trpc/trpc/pull/3528
I guess the adding of
mutationKey
was forgotten about?GitHub
expose getQueryKey on mutation procedures by hdwatts ยท Pull Request...
๐ฏ Changes
In #3302 getQueryKey was exposed for all query procedures. I was hoping to be able to use the feature for setMutationDefaults - however the method was not exposed on mutation queries.
Hap...
H
Haaxor1689โข367d ago
After some investigation, turns out that for whatever reason,
onSettled
and onMutate
work just fine. onSettled
works only if I directly put it into hook call itself.
oh I found the culpritH
Haaxor1689โข367d ago
Ok, made a PR with proposed fix ๐ https://github.com/trpc/trpc/pull/4371
GitHub
Fix some query and mutation defaults being overwritten in hook wrap...
Closes #
๐ฏ Changes
Wrapper around useMutation hook was not honoring options set by getMutationDefaults hook at all. Default options are now loaded as well and used as a fallback to wherever opts ar...
4.8KMembers
View on DiscordMore Posts
Using tRPC in React SPA with Django backendis that possible? Do I need to create an AppRouter and put that inside my django backend files? How Typing a shared TRPC provider for testingContext:
- We have a monorepo with several micro-frontends which use Next.
- We're moving to using tResponse promise resolves before endpoint finished processingI want to interact with OpenAI's API in my Next.js + tRPC app. It seems that the my frontend is not tRPC onErrorI am using tRPC with Fastify and would like to be able to report issues when we get an error.
httpsCode structure for a large monorepo using nx + tRPCWe have a large monorepo with a single tRPC API that will be used by several web clients and other cDoes tRPC work with Clerk and Vercel Edge functions?So the answer is yes, at least locally, but I when I deploy to Vercel I get nothing. Trying to work TRPCClientError when creating a db entry without `updatedAt` value?Guys, this is my prisma schema:
```
model User {
id Int @id @default(autoincrement())
Type error: The inferred type of 'trpc' cannot be named without a reference....```./src/lib/api.ts:21:14
@driveorg/dashboard:build: Type error: The inferred type of 'trpc' cannot Decision on authI am using create-t3-app for my app , with next-auth (twitter, discord, google) . Now i am using samWhy does this starter with Prisma have it's own postinstall script?Prisma has it's own postinstall hook/script: <https://www.prisma.io/docs/concepts/components/prisma-