在我的onBeforeLift函数中,我想执行两个异步redux动作,其中第二个取决于第一个。
这是我当前的代码:
import React from "react";
import { BrowserRouter } from "react-router-dom";
import { render } from "react-dom";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/es/integration/react";
import App from "./containers/App";
import configureStore from "./redux/store";
import { LanguageActions, VersionActions } from "./redux/actions";
// Extract persistor and store configuration
const { persistor, store } = configureStore();
// Search for the div element with the id 'root' in the index.html file
const mountNode = document.querySelector("#root");
const renderApp = () => {
// Execute the following redux actions before gate lifts and app is being displayed
const onBeforeLift = () => {
store.dispatch(VersionActions.requestVersion());
store.dispatch(
LanguageActions.fetchTranslatedLabels(new Date().getFullYear())
);
};
// PersistGate delays rendering of app's UI until
// persisted stated has been retrieved and saved to redux
render(
<Provider store={store}>
<PersistGate persistor={persistor} onBeforeLift={onBeforeLift}>
<BrowserRouter>
<App />
</BrowserRouter>
</PersistGate>
</Provider>,
mountNode
);
};
renderApp();
根据GitHub上的一个问题,应该可以,但我想不出一种解决方案。目标是存储第一个动作的响应值,并使用它来执行第二个动作,而不是new Date(().getFullYear()