【问题标题】:Cannot update a component from inside the function body of a different component ,navigate problem无法从不同组件的函数体内更新组件,导航问题
【发布时间】:2021-10-07 07:52:15
【问题描述】:

我的管理员主页

导出默认函数 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>
);

} }

【问题讨论】:

    标签: reactjs react-native react-navigation


    【解决方案1】:

    这是answered before,但在按钮的 onPress 属性中,您应该使用像这样的箭头函数。

    <Button title="Add / Delete products"  
            onPress={ () => { props.navigation.navigate("addproduct")} }
    />
    

    【讨论】:

      猜你喜欢
      • 2020-11-06
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多