I have a button with an onClick calling a function that unfortunately I can't change. This function performs a login to the application:
<Button onClick={() => signIn()}>
but I need to execute some other code, to check if the user has checked a few checkboxes. Is there a way to call another function before the current one, and prevent the function call if the first one return false?
You can get the old onclick value, then replace it with your function that calls the original when it's done checking.
let oldFunc = button.onclick;
button.onclick = function(event) {
// code to check if the checkboxes are checked
if (boxes_checked) {
if (typeof oldFunc == 'string') {
eval(oldFunc);
} else {
return oldFunc(event);
}
}
}