【发布时间】:2020-07-27 09:23:56
【问题描述】:
我正在创建一个函数来更新我的数据库中的一些信息,并以 react 作为前端。问题是,在我更新数据库中的项目后,我希望它是实时的,但每次我进行新的更新时,我都必须再次刷新页面。 我的代码如下所示。
edit = async (id, quantity, action) => {
if (action === "inc") {
await this.props.updateItem(id, quantity + 1);
}
if (action === "dec") {
await this.props.updateItem(id, quantity - 1);
}
history.push("/");
history.push("/cart");
};
这是我用来更新项目的功能。 请帮忙,在此先感谢。
【问题讨论】:
-
有什么问题?在 BE 调用完成状态更新或 redux 存储更新后更新您的项目。
-
我不想在我的代码中添加 last 到 history.push() 行。此外,我的数据仅在初始请求时来自 redux。
标签: javascript reactjs redux navigation browser-history