useMutation adds undefined to TResult of MutateFunction type
See original GitHub issueDescribe the bug
useMutation
changes the return type of provided promise by adding undefined
to it.
To Reproduce
const apiCall = () => new Promise<string>(resolve => resolve());
const useExample = async () => {
const [mutateCall] = useMutation(apiCall);
const response = await apiCall(); // string
const mutateR = await mutateCall(); // string | undefined
};
Wrapping a function in useMutation
adds a undefined
to it’s returned promise
Expected behavior
The provided function’s return type should not be changed.
Desktop (please complete the following information):
- Version: 23
Additional context
I don’t see any reason why this would be required. Together with #1077 this is making migration to this library pretty unnecessarily painful by imposing this opinionated types.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:21
Top Results From Across the Web
useMutation adds undefined to TResult of MutateFunction type
This function will fire when the mutation is successful and will be passed the mutation's result. Fires after the mutate-level onSuccess handler ...
Read more >Mutations in Apollo Client - Apollo GraphQL Docs
The useMutation result is a tuple with a mutate function in the first position and an object representing the mutation result in the...
Read more >How to declare useMutation return type in 'react-query'
With the types that I put on api and setFriendCode , I get <Response, unknown, Params, unknown> . const object = useMutation( setFriendCode...
Read more >Apollo useMutation React hook - Hasura
We will use the Apollo Client useMutation from @apollo/client in React app as an example ... the first argument of the result tuple...
Read more >Mutations | TanStack Query Docs
For this purpose, React Query exports a useMutation hook. Here's an example of a mutation that adds a new todo to the server:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think the PR above fixes this issue. v3 will be awesome!
What about providing two mutate functions? One for callbacks and for promises?
Callback version:
Promise version:
Then
mutate
would return nothing,mutateAsync
would return a promise andthrowOnError
can be removed.