react-redux - getServerSideProps 未填充状态
问题描述
我正在尝试在我的 index.js 页面中使用 getServerSideProps 填充应用程序状态,这是文件的内容:
import Navbar from "../components/Layouts/Navbar";
import MainBanner from "../components/Layouts/MainBanner";
import Footer from "../components/Layouts/Footer";
import { loadContent } from "../store/appSlice";
import { wrapper } from "../store/store";
const Index = () => {
return (
<>
<Navbar />
<MainBanner />
<Footer />
</>
);
};
export const getServerSideProps = wrapper.getServerSideProps(store => async ({ req }) => {
await store.dispatch(loadContent());
});
export default Index;
如果 loadContent 看起来像这样:
const loadContent = () => async dispatch => {
dispatch(contentRequested());
return fetchContent()
.then(data => {
console.log(data);
dispatch(serviceSuccess(data.services));
dispatch(testimonySuccess(data.testimonials));
return dispatch(contentSuccess(data));
})
.catch(error => {
return dispatch(contentError(error));
});
};
在 console.log 中,正在检索数据,但接下来的 2 个调度不会填充状态。有什么建议么?
谢谢!
解决方案
推荐阅读
- windows - Powershell -- 命令抛出异常,重试上一个命令(循环)直到成功
- java - 如何裁剪打印屏幕内的图像?
- typescript - 是否可以在 Typescript 中创建类后向其添加装饰器?
- python - 熊猫每年对特定月份范围内的每个值求和
- python - 如何在 PyDev 中发送脚本路径进行调试,而不是在脚本中插入 settrace?
- python - 优化python程序同时解析两个大文件
- python - `sympy.codegen.ast` 可以与 `sympy.utilities.autowrap` 一起使用吗?
- nginx - Nginx URL 重写 - Prestashop
- sql - 如何使用 xpath 从 xml 列的特定部分获取所有 xml 元素?
- android - Pepper Robot - 如何通过 DialogFlow 启动平板电脑应用程序?