如何在React Native中将函数调用作为道具传递到组件中



我正试图将函数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);
};

事实上,我有很多按钮,每个按钮都有不同的功能调用。因此,它需要通过道具来表达。需要帮助!

更改此项:

functionCall="updateProfile"

到此:

functionCall={updateProfile}

最新更新