acceptAccess = (item) => {
        const {accept} = this.state;
        let {errors} = this.state;
            if (!isUndefined(accept.text)){
                if (accept.text.length > 0){
                    this.setState({pending: true});//here
                    Global.showSuccessMessage("Задача выполнена");
                    this.setState({postData: {task_guid: this.props.selectedApprove.id, result: item.buttonCode, comment: this.state.accept.text}});
                    setTimeout(
                        function () {
                            DocumentsApi.sendApprove(this.state.postData).then(this.props.onClose());
                        }.bind(this),
                        1000
                    );
                }
            }
        } else  {
            this.setState({pending: true});//here
            Global.showSuccessMessage("Задача выполнена");
            this.setState({postData: {task_guid: this.props.selectedApprove.id, result: item.buttonCode, comment: this.state.accept.text}});
            setTimeout(
                function () {
                    DocumentsApi.sendApprove(this.state.postData).then(this.props.onClose());
                }.bind(this),
                1000
            );
        }
        this.props.update;
    };
为什么未决没有帮助?有时我有双重要求?解决此问题我需要做什么?谁知道在这种情况下该怎么办?

最佳答案

您可以使用lodash throttle 来防止任何事件多次触发

https://lodash.com/docs/4.17.15#throttle

例:

const clickHandler = _.throttle(e => acceptAccess(e), 1000, { trailing: false });
...
<button onClick={()=>clickHandler(e)}>

09-16 16:35