I have a button which sends an async request but I only want to send this if a variable is false. I have tried to follow this question but I keep getting errors
This is the original onClick
onClick={async () => {
const CompleteCA = async () => {
try {
if (!statusFinal) {
await sendTransaction({
},
});
}
await updateCA({
variables: {
id: CA,
},
});
history.push('/');
} catch (error) {
logError(error);
}
};
CompleteCA();
}}
After adding conditional:
onClick={async () => {
testFlag ? alert("flag is true") :
const CompleteCA = async () => {
try {
...... rest of function
}
};
CompleteCA();
}}
I'm getting all the lines underlined since const can't be declared inside onClick, but I'm not sure how to move this out to another function and keep the async intact