I'm attempting to delay a button click so that the library I'm using can make a quick api call for validation. I'm currently using an arrow function in react and attempting setTimeout. However it appears this is triggering a call on page load for some reason. Here's my code.
onClick={this.handleCardSubmit}
handleCardSubmit = setTimeout(() => {
this.setState({ showLoaderForPayment: true });
const { collectJs } = this.state;
collectJs.startPaymentRequest();
this.setState({ isPaymentRequestCalled: true });
}, 500);
onClick={this.handleCardSubmit}try thisonClick={()=>this.handleCardSubmit()}evt.preventDefault(), you are not returningfalse; if your button is a submit button, it will do what submit buttons do: submit.onClick={()=>setTimeout(() => {this.handleCardSubmit()},500)}..just asking ?