Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose useMutationState for optimistic updates #5940

Open
1 task done
danilofuchs opened this issue Aug 13, 2024 · 1 comment
Open
1 task done

feat: expose useMutationState for optimistic updates #5940

danilofuchs opened this issue Aug 13, 2024 · 1 comment
Labels
✅ accepted-PRs-welcome Feature proposal is accepted and ready to work on

Comments

@danilofuchs
Copy link

danilofuchs commented Aug 13, 2024

Describe the feature you'd like to request

Optimistic updates in React Query 5 can be simpler by using the useMutationState anywhere in the application to hook into a running mutation state and variables

https://tanstack.com/query/latest/docs/framework/react/guides/optimistic-updates#via-the-ui

Describe the solution you'd like to see

I would love if tRPC exposed a api.createPost.useMutationState() hook

Describe alternate solutions

  1. I could use useMutationState() on my own and reconstruct the mutation key, but I understand this is an implementation detail and not exposed by tRPC
  2. This API could be exposed in the apiUtils realm: apiUtils.createPost.mutationState()

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@JonParton
Copy link
Contributor

Just FYI the generated query key is exposed using the getQueryKey() helper just for this kind of use!

I'll leave for others to comment on including to the trpc api itself!

@KATT KATT added the ✅ accepted-PRs-welcome Feature proposal is accepted and ready to work on label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ accepted-PRs-welcome Feature proposal is accepted and ready to work on
Projects
None yet
Development

No branches or pull requests

3 participants