[英]Passing a memoized function to onPress of a component issue
Assume I have the following component:假设我有以下组件:
<TouchableOpacity
style={...}
onPress={() => func(x)}
>
<TouchableOpacity/>
and func() defined as follows:和 func() 定义如下:
const func = (x) => {console.log("help please")}
This work as it should.这项工作应该如此。 However, once I memoize func() as follows:
但是,一旦我将 func() 记忆如下:
const func = useMemo(()=>throttle(500,true, (x)=>{console.log("help please")}
I get the following error:我收到以下错误:
TypeError: callback.apply is not a function. (In 'callback.apply(self, arguments_)', 'callback.apply' is undefined)
Note: throttle was imported:注意:油门是进口的:
import { throttle } from "throttle-debounce";
尝试删除true
的参数,因为它没有在文档中指定
throttle(500, (x)=>{console.log("help please")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.