mutation typing #1601
Unanswered
hyusetiawan
asked this question in
Q&A
mutation typing
#1601
Replies: 2 comments 7 replies
-
|
I call and the error message is : |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You'll need to explicitly type the callback from the 2nd parameter and on, those types will be inferred in the returning mutation function. There are two common styles to type it: Direct importsimport { type Mutation, type Variables } from './gqty';
const [login, mutationStates] = useMutation((mutation, args: Variables<Mutation["login"]>) => {
const token = mutation.login(args);
return token;
});
// Later in your code
<Button onClick={() => {
login({ username, password });
}}>Login</Button>Curated inputsconst [login, mutationStates] = useMutation((mutation, username: string, password: string) => {
const token = mutation.login({ username, password });
return token;
});
// Later in your code
<Button onClick={() => {
login(username, password);
}}>Login</Button> |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
im following the mutation for reach as shown here: https://gqty.dev/guides/react/write
but I am not getting the typing when I call the returned mutation function, like so:


but inside the callback, I am able to see the typing properly:
is there a way to type the
loginfunction?Beta Was this translation helpful? Give feedback.
All reactions