如果用户单击"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/