getstate java,Redux getState在服务器上返回initialState

我正在构建一个同构反应应用程序,并在用户发送请求时执行以下任务:

1)假设用户命中 /about-us ,react-routers matchPath 找到适当的组件并返回它 .

2)调用名为fetchData的静态函数,该函数调度动作 aboutPageContent() . 3)一旦在服务器上解析了promise,就会调用getState以获得更新状态 but it returns the initialState of aboutPage and not the newly updated state .

Reducer获得响应但不返回新状态 . (只有在服务器调度操作时才会发生这种情况) .

服务器上的getState返回:

{

aboutUs:{

founders:[{}]

story: ""

}

}

但它应该返回:

{

aboutUs:{

founders:[{name: 'abc'}]

story: "some random story"

}

}

server.js

app.get("*", (req, res) => {

const memoryHistory = createMemoryHistory(req.url)

const currentRoute = routes.find(r => matchPath(req.url, r))

const store = configureStore({}, memoryHistory)

if (currentRoute && currentRoute.component.fetchData) {

Promise.all(currentRoute.component.fetchData(store, req.url)).then(() => {

const content = (

)

const htmlContent = renderToString(content)

const preloadedState = store.getState()

const html = renderToStaticMarkup()

res.status(200)

res.send(html)

})

}

})

aboutPageContainer.jsx

static fetchData = (store) => [store.dispatch(aboutPageContent())]

preloadedState被分配给 window.__data . 并且在client.js上调用 window.__data 以加载客户端存储 .

我做错了吗?这是我的第一个反应 - 同构应用程序 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值