reactjs - 无法从不同组件的函数体内更新组件,导航问题
问题描述
我的管理员主页
导出默认函数 AdminHP(props) {
return (
<View style={styles.container}>
<ImageBackground source={image} resizeMode="cover" style={styles.image}>
<View style={styles.Button}>
<Button title="Add / Delete products" onPress={ props.navigation.navigate("addproduct")}/>
</View>
<View style={styles.Button}>
<Button title="Check product list" />
</View>
</ImageBackground>
</View>
)
}
app.js 导出默认类 App 扩展组件 {
使成为() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Login" >
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="AdminHP" component={AdminHP} />
<Stack.Screen name="UserHP" component={UserHP} />
<Stack.Screen name="addproduct" component={addproduct} />
</Stack.Navigator>
</NavigationContainer>
);
} }
解决方案
之前已经回答了这个问题,但是在按钮的 onPress 属性中,您应该使用像这样的箭头功能。
<Button title="Add / Delete products"
onPress={ () => { props.navigation.navigate("addproduct")} }
/>
推荐阅读
- python - Kivy 无法获得窗口,中止
- javascript - react-native:分享 api 传递 base64 字符串而不是图像到 WhatsApp
- c# - DataWriter/DataReader 关系
- android - Android - RecyclerView 被 BottomNavigationView 遮挡
- javascript - 如何在 PWA 和 ReactJS 中创建动态 manifest.json 文件?
- unity3d - 在 ARCore + Unity 中为 AugmentedImages 创建预制件
- python - 尝试访问所有数据时,Flask WTForm 数据返回 csrf_token
- apache-spark - 在 spark-shell 中安排 spark 作业
- sql - 如何在 Oracle 中使用 MERGE 更新下表?
- jenkins - 如何在本地编译 Jenkins Pipeline Groovy?