Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 将lodash节流阀与React文本输入和Typescript一起使用_Reactjs_Typescript_Lodash_Throttling - Fatal编程技术网

Reactjs 将lodash节流阀与React文本输入和Typescript一起使用

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)(

即使在阅读了大量的文档之后,我仍在努力使这个文本输入节流阀在react中工作

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);}
/>