【发布时间】:2022-01-12 17:27:37
【问题描述】:
我正在 Redux 上创建一个 Reddit 客户端,我在应用中触发了 2 个商店调度:
// App()
const dispatch = useDispatch();
useEffect(() => {
const stateMatch = window.location.href.match(/state=([^&]*)/);
const codeMatch = window.location.href.match(/code=([^&]*)/);
if ((stateMatch && codeMatch) || localStorage.getItem("access_token")) {
dispatch(fetchUser());
dispatch(fetchSubs());
}
});
...
但是,我希望 fetchUser() 在 fetchSubs() 开始之前运行并完成,因为前者目前似乎在运行时破坏了后者的 API 调用。我该如何解决这个问题?
【问题讨论】:
-
你能告诉我fectchuser吗
-
@abhipatil See it here
标签: javascript reactjs redux