Javascript 为什么调用取消公告的函数会抛出;不是一个函数;错误
我正在创建一个搜索输入,它使用lodashJavascript 为什么调用取消公告的函数会抛出;不是一个函数;错误,javascript,reactjs,lodash,Javascript,Reactjs,Lodash,我正在创建一个搜索输入,它使用lodashdebounce延迟输入时的请求 constructor(props) { super(props); this.state = { query: "" }; this.debouncedFetchSearchList = debounce(this.fetchSearchList, 500); } 以下是我用于获取列表的函数: fetchSearchList = (query: string) =>
debounce
延迟输入时的请求
constructor(props) {
super(props);
this.state = {
query: ""
};
this.debouncedFetchSearchList = debounce(this.fetchSearchList, 500);
}
以下是我用于获取列表的函数:
fetchSearchList = (query: string) => {
if (query.length >= 3) {
this.props.setSearchList(query);
}
};
updateQuery = (id: string, value: string) => {
const query = value;
this.setState({
query: query
});
this.debouncedFetchSearchList(query);
};
JSX:
使用此设置键入时,会出现以下错误:
“未捕获类型错误:\ this.debouncedFetchSearchList不是函数”
如果我调用console.log(this),我可以看到函数就在那里,它的值是一个lodash包装器
我是不是错过了一些明显的东西?所以最后这是一个愚蠢的错误 我输入的不正确 我有:
从“lodash”导入去盎司代码>
应该是:import{debounce}来自“lodash”代码>
以前我认为导入是正常的,因为我认为如果导入错误,就会出现错误。不,您不会错过任何东西。您发布的代码无法解释此问题。考虑提供一种复制它的方法。这个问题应该被删除或关闭。这是一个印刷错误,对其他人没有帮助。
<TextInput
type="text"
id="search-items"
onChange={this.updateQuery}
label={I18n.search}
placeholder={I18n.search}
className="search-items"
/>