当用户停止输入时验证输入 - ReactJs

问题描述

我只想在用户停止输入时执行输入验证。

<SmallInput
   onChange={() => {
        if (unitsPerUser < this.state._unitsPerUser) {
                unitsPerUserError = true;
                this._updateUnitsPerUser("");
                this.setState({
                      unitsPerUser: "",unitsPerUserError,unitsPerUserErrorMsg: `Per user units cannot be less than ${this.state._unitsPerUser}`,});
        }
   }}
/>

我不想在 keyupkeydown 上执行此验证,而是在用户完成输入时执行此验证。

我如何使用任何工具(例如 debounce)来实现这一点?提前致谢。

编辑 - 我试过这个,但它似乎不起作用 -

<SmallInput
   onChange={() => {
        if (unitsPerUser < this.state._unitsPerUser) {
                let typingTimer;
                clearTimeout(typingTimer);
                setTimeout(() => {
                     unitsPerUserError = true;
                     this._updateUnitsPerUser("");
                     this.setState({
                             unitsPerUser: "",});
                 },1000);
        }
   }}
/>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)