【发布时间】:2016-12-01 14:11:38
【问题描述】:
我正在构建一个在按键上执行 API 请求的函数,但我希望它去抖动。
这目前不起作用并产生错误:lodash.js:10319 Uncaught TypeError: Expected a function
这是一个带有控制台日志而不是异步请求的代码 sn-p,它也不起作用!
import React from 'react';
const _ = require('lodash');
const method = () => {
return _.debounce(testFunc(), 3000);
};
const testFunc = () => {
console.log('echo echo test test');
};
const SearchBox = ({ onTypingSearch, searchTerm }) => (
<form>
<p>Search: {searchTerm}</p>
<input
onChange={(e) => {
console.log(e.target.value);
onTypingSearch(e.target.value);
console.log(method);
method();
}}
value={searchTerm}
/>
</form>
);
export default SearchBox;
【问题讨论】:
标签: javascript reactjs redux lodash