javascript - 在 React Native 中重新渲染 - 问题

标签 javascript reactjs react-native rendering

如果用户单击"is"从列表中删除该项目,我在 native 中有此代码。但该元素仍在包中,直到刷新为止! 单击删除时如何重新渲染?

  const bagProducts = this.props.allProducts;
    const productId = this.props.deleteProductAction(this.props.id).id;
    var result = bagProducts.filter(x => {
      return x.id == productId;
    })[0];

  <TouchableOpacity
            style={styles.bagItemButtons}
            onPress={() => {
              Alert.alert(
                "Alert",
                "Are you sure wnat do delete ?",
                [
                  { text: "NO", onPress: () => console.log("Cancel pressed") },
                  {
                    text: "Yes",
                    onPress: () => {
                      bagProducts.splice(result, 1);
                    }
                  }
                ],
                { cancelable: true }
              );
            }}
          >
            <Text style={styles.bagItemButtonText}>{t("delete")}</Text>
          </TouchableOpacity>

最佳答案

将列表项置于状态并更新它将呈现列表的状态

关于javascript - 在 React Native 中重新渲染 - 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50328945/

相关文章:

javascript - React.js 父组件和同级组件 : Keep only one nav bar div expanded at a time

javascript - 在 React-Native 中访问 this.state

react-native - 如何在有错误的项目中使用外部库?

reactjs - setCount(prev => prev + 1) 和 setCount(count + 1) 有什么区别?

javascript - React JS 与 Redux 似乎不会重新渲染

android - React Native 陷入配置 React-Native-gesture-handler 的困境

javascript - 套件脚本 2.0 : Retrieve the values of the parameters passed from the sales order into the suitelet using the getParameter

Javascript,乘以最后一个循环数

javascript - HTML 表格单元格值计数器

javascript - Backbone - 插入 JavaScript 来操作 DOM 的最佳位置在哪里