feat: expose useMutationState for optimistic updates
Nobody has claimed this yet.
- 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
- 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 - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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