【发布时间】:2020-02-13 06:16:34
【问题描述】:
我有这个限制文本输入的代码,但我也希望它限制一个方法调用,该方法调用似乎正在阻止文本限制工作。
import { throttle } from 'lodash';
...
<input
type="text"
onChange={(e): void => throttledTextInput(e.target.value)}
style={{ outline: 'none' }}
/>
...
const throttledTextInput = throttle((text) => handleThrottledText(text), 1000);
...
const handleThrottledText = (text: string): void => {
console.log(text); // without the below two lines it works fine
const textInputMessage: Array<Action> = [];
// but when calling the below, the throttling stops working and it
};
我该如何解决这个问题?
【问题讨论】:
-
这是在功能组件中吗?
-
@Dominic 是的
标签: reactjs typescript lodash throttling