trpc / trpc/trpc

feat: expose useMutationState for optimistic updates

Open
#5,940 2 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

✅ accepted-PRs-welcome
Dominant language
TypeScript
Stars
40.6k
Forks
1.7k
Avg merge
1d 22h
Merged PRs (30d)
22

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the React Query optimistic updates guide linked in the issue and compare it with tRPC's existing React mutation-hook API. Define the exposed useMutationState behavior for api.createPost, including access to running mutation state and variables without reconstructing the mutation key.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
api, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.