问题描述
我正在尝试将我的函数 updateProfile
作为道具传递给如下所示的 Button 组件。当我按下按钮时,该功能不起作用,应用程序崩溃。
这里是按钮组件的代码。
const Button = (props) => {
return (
<>
<TouchableOpacity
style={styles.buttonContainer}
disabled={props.disabled}
onPress={props.functionCall}
>
<Text style={styles.buttonText}>{props.title}</Text>
</TouchableOpacity>
</>
);
};
这是我的使用方法
<Button disabled={isLoading ? true : false} functionCall="updateProfile" title="Edit Profile"/>
const updateProfile = () => {
navigation.navigate("updateProfile",member);
};
实际上,我有很多按钮,每个按钮都有不同的功能调用。所以,它需要通过 props 发送。需要帮助!
解决方法
改变这个:
functionCall="updateProfile"
为此:
functionCall={updateProfile}