Javascript 如何在React Native中将组件中的函数调用作为道具传递?
我正在尝试将我的函数Javascript 如何在React Native中将组件中的函数调用作为道具传递?,javascript,reactjs,react-native,frontend,mern,Javascript,Reactjs,React Native,Frontend,Mern,我正在尝试将我的函数updateProfile作为按钮组件中的道具传递,如下所示。当我按下按钮时,该功能不工作,应用程序崩溃 下面是按钮组件的代码 const Button = (props) => { return ( <> <TouchableOpacity style={styles.buttonContainer}
updateProfile
作为按钮组件中的道具传递,如下所示。当我按下按钮时,该功能不工作,应用程序崩溃
下面是按钮组件的代码
const Button = (props) => {
return (
<>
<TouchableOpacity
style={styles.buttonContainer}
disabled={props.disabled}
onPress={props.functionCall}
>
<Text style={styles.buttonText}>{props.title}</Text>
</TouchableOpacity>
</>
);
};
实际上,我有很多按钮,每个按钮都有不同的函数调用。所以,它需要通过道具来表达。需要帮助 改变这一点:
functionCall="updateProfile"
为此:
functionCall={updateProfile}
尝试像这样传递函数:
functionCall={updateProfile}
您正在以字符串的形式传递它。。在{}中将其作为函数传递谢谢,亲爱的,虽然这是一个小错误,但我试图修复它,但它花费了我很长时间。
functionCall="updateProfile"
functionCall={updateProfile}