lodash debounce错误:未接收的TypeError:期望功能
我正在尝试使用debounce
函数,以避免打字并在表中搜索某些内容时进行多个调用。这就是我所做的 -
onChange={(_event, searchText) => React.useCallback(debounce(void setSearchText(searchText), _searchDebounceWaitTime), [])}
它给出了一个错误,说明未访问的TypeError:预期函数
我在做什么错?我在网上发现的大多数解决方案都做了类似的事情。
注意:我也尝试做 -
onChange={(_event, searchText) => React.useCallback(debounce(searchText => setSearchText(searchText), _searchDebounceWaitTime), [])}
但是这次我收到以下错误 - 无效的挂钩调用。钩子只能在功能组件的主体内部调用。这可能是出于以下原因之一:
pls帮助。
I am trying to use the debounce
function to avoid multiple calls when I'm typing and searching something in a table. This is what I have done -
onChange={(_event, searchText) => React.useCallback(debounce(void setSearchText(searchText), _searchDebounceWaitTime), [])}
It gives an error stating Uncaught TypeError: Expected a function
What am I doing wrong ? Most solutions I found online have done a similar thing.
Note: I also tried doing -
onChange={(_event, searchText) => React.useCallback(debounce(searchText => setSearchText(searchText), _searchDebounceWaitTime), [])}
but this time I got the following error - Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
Pls help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,正如错误状态所示,React钩子不能在JSX中。应该是这样的:
然后,为了进行审问,您要寻找的是一个记忆的功能:
First of all, as the error states, a react hook cannot be in the jsx. It should be like this:
Then, for a debounce, what you are looking for is a memoized function: