-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Question: How can I send parameters to the mutations ? #96
Comments
Typescript is reporting there are no 'options' property. I recommend this vscode extension to help you understand typescript errors. useSecurityServiceLogin is a mutation, not a query; your example shows you calling it like a query. Check out this guide to mutations: https://tanstack.com/query/latest/docs/framework/react/guides/mutations Right now, only GET requests are generated as queries in this library. I have a PR open that expands the documentation on using mutations. #97 Your component should look something like the following: const LoginButton = ({
userName,
password,
jolokiaHost,
jolokiaPort,
protocol,
broker,
ordinal,
}: LoginProps) => {
const { mutate: loginMutation, isSuccess, isError, isPending } = useSecurityServiceLogin({
onSuccess: (value) => {
console.log('Login result', value);
},
onError: (error) => {
console.error('Failed to login', error);
},
});
const login = async () => {
console.log('Attempting to login...');
await loginMutation({
brokerName: getBrokerKey(broker, ordinal),
userName,
password,
jolokiaHost,
port: jolokiaPort,
scheme: protocol,
});
};
const buttonText = isPending ? 'Logging in...' : 'Login';
return (<button disabled={pending} onClick={() => login()}>{buttonText}</button>);
} |
Thanks a lot, I'm going to give it a try. |
I'm closing the issue as your answer resolved my question. Thanks! |
The generated code creates a mutation for me:
However, I don't know how to use it, because if in the code I'm doing something like:
I'm getting errors from the linter
I can make it work like this:
But I would prefer to use the mutation hook. Any idea on what I'm doing wrong?
Thanks
The text was updated successfully, but these errors were encountered: