Api.GET({
url: USER_LOGIN_AUTH,
payload: null,
onSuccess: response => {
window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true;
store.dispatch(getUserAction(response.data));
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>,
document.getElementById("root")
);
},
onFailure: () => {
ReactDOM.render(<Unauthorized />);
}
});
如何确保在行store.dispatch
执行之前,ReactDOM.render
及其相应的化简器已设置了新状态。
我希望在设置初始状态之前不渲染我的应用。
谢谢
答案 0 :(得分:0)
使用Promise可以帮助您
Api.GET({
url: USER_LOGIN_AUTH,
payload: null,
onSuccess: response => {
window.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true;
new Promise(function(resolve, reject) {
try {
resolve(store.dispatch(getUserAction(response.data)));
} catch (error) {
reject(error);
}
}).then(store => {
ReactDOM.render( < Provider store = {store} >
<BrowserRouter >
<App />
</BrowserRouter> </Provider>,
document.getElementById("root")
);
})
},
onFailure: () => {
ReactDOM.render( < Unauthorized / > );
}
});