首页 > 解决方案 > 如何在 React 组件中等待 Redux 状态更新?

问题描述

我有以下动作创建者,我需要在 React 组件中等待。它需要运行完成(在reducer 更新存储之后),因为React 组件需要访问它。如何在我的 React 组件中使用以下内容?这是实验性 Suspense API 将提供的吗?

await updateLocation()
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(
            (res) => {
                if (res) {
                    reverseGeoCodeCoords(res)
                        .then((d) => {
                                   dispatch({
                                            type: UPDATE_USER_LOCATION,
                                            payload,
                                        });
                                    }
                                }
                            }
                        })
                        .catch((err) => {
                            console.log(err);
                        });
                }
            },
            (err) => {

            }
        );
    } else {
        console.log("Browser doesn't support geolocation.");
    }
};```

标签: reactjsreact-redux

解决方案


推荐阅读