React Debounce calling multiple time onPress event in class component

20 Views Asked by At

I am using react class component but the issue is If I am clicking multiple time on the button the alert is triggering being multiple time. Any help will be appreciated.

class EventController {
timer: any = null;

handleCreateEventSubmit() {
    clearTimeout(this.timer);
    this.timer = setTimeout(async () => {
        Alert.alert('Called');
    }, 1000);
}

render() {
    return (
        <Button onPress={this.handleCreateEventSubmit}>Submit</Button>
    );
  }
}

Let me know if its because of re-rendering or what triggering it again when clicking multiple time on same time.

0

There are 0 best solutions below