reactjs - _app (nextjs) 中的调度操作
问题描述
它在 _app.js 中,我们必须将我们的商店和 saga 与“withredux”和“withReduxSaga”连接起来,但是,是否也可以在 _app.js 中调度操作?像那样 :
async getInitialProps({ Component, ctx }) {
ctx.store.dispatch(fetchDataRestaurant(1));
}
就我而言,它不起作用,它仅在带有“this.props.store.dispatch()”的组件中起作用
仅当我更改页面时,我的动作才最终在“getInitialProps”中调度......当应用程序加载时,动作没有调度,有人可以帮我吗?
谢谢你
解决方案
你可以试试redux-axios-middleware。它可能会解决问题。
static async getInitialProps ({ store }) {
await store.dispatch(fetchDataRestaurant())
return { restaurant: getRestaurant(store.getState()) }
}
推荐阅读
- reactjs - TS2339:属性 'defaultProps' 不存在于类型 '(props: any) => detailedReactHTMLElement<{ className: string; }, HTML元素>'
- go - readString 与 readLine
- java - 我可以将扩展类中的变量类型强制为 Java 中的子类型吗?
- git - 为什么我在 Heroku 上收到意外的远程拒绝?
- python - 更改命令的输入顺序
- html - 父 html 元素忽略子元素的填充
- python - ftplib获取命令返回值
- spring - Spring Security REST 登录
- r - R tidyverse根据关键字条件更改单元格内容(字符串)的方法,其中包含另一个单元格的内容加上文本
- reactjs - React-Redux:未捕获的类型错误:无法读取未定义的属性“名称”