【发布时间】:2021-05-31 11:03:42
【问题描述】:
我正在尝试将我的函数 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} -
您将其作为字符串传递..将其作为函数传递给 {}
标签: javascript reactjs react-native frontend mern