Reactjs 将lodash节流阀与React文本输入和Typescript一起使用
即使在阅读了大量的文档之后,我仍在努力使这个文本输入节流阀在react中工作Reactjs 将lodash节流阀与React文本输入和Typescript一起使用,reactjs,typescript,lodash,throttling,Reactjs,Typescript,Lodash,Throttling,即使在阅读了大量的文档之后,我仍在努力使这个文本输入节流阀在react中工作 import { throttle } from 'lodash'; ... <input type="text" onChange={(e): void => throttle(handleTextInput, 1000)(e)} /> 从“lodash”导入{throttle}; ... 节气门(handleTextInput,1000)(
import { throttle } from 'lodash';
...
<input
type="text"
onChange={(e): void => throttle(handleTextInput, 1000)(e)}
/>
从“lodash”导入{throttle};
...
节气门(handleTextInput,1000)(e)}
/>
很明显我做错了什么,谢谢你的帮助 在您的代码示例中,
e
在语法上是错误的。将代码更改为上面的代码,并告诉我是否成功
<input type="text"
onChange={() => throttle(handleTextInput, 1000)}
/>
throttle(handleTextInput,1000)}
/>
现在您正在调用throttle
函数,同时为输入定义onChange。您必须为等待后需要调用的油门提供一个函数。试试这个-
throttledInput = throttle(input => this.handleTextInput(input), 1000);
...
<input
type="text"
onChange={(e) => this.throttledInput(e.target.value);}
/>
throttledInput=throttle(输入=>this.handleTextInput(输入),1000);
...
this.throttledInput(e.target.value);}
/>