简体   繁体   English

将记忆函数传递给组件问题的 onPress

[英]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.

相关问题 React Native将Component / Object属性传递给OnPress函数 - React Native passing Component/Object property to OnPress function 将 memoized 函数作为道具传递给 React 组件会导致我无法修复的 Typescript 错误 - Passing memoized function down into React Component as a prop causes Typescript error which I can't fix 将值传递给 onPress 以触发 function - Passing a value to onPress to trigger a function 将 onPress 重定向传递给子组件 React Native - Passing onPress redirect to child component React Native React native 使用来自 onPress 的传递值 function 显示另一个组件视图 - React native using the passing value from onPress function show another component view 记忆组件的子组件是否也被记忆? - Are child components of a memoized component memoized too? 在 Modal 中传递 function 时 React Native “onPress 不是函数” - React Native “onPress is not a function” when passing function in Modal 如何在Redux连接的组件的函数内部模拟onPress事件 - How to simulate onPress event inside a function for redux connected component 使用记忆化的 React 组件重新绘制组件时出错 - Error in Component re draw with memoized React component onPress 不适用于可动画组件 - onPress not working on Animatable component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM