I need to call two apis parallely. And this is important as I want to keep the time for the page to load
to minimum.
If I call the two apis (like below) in
componentDidMount
then would it be asynchronous or not.
class Test extends Component{
constructor(args) {
super(args)
this.state = {
...
};
...
}
componentDidMount() {
//api1() and api2() are like .get(url).then()
this.props.dispatch(actions.api1())
this.props.dispatch(actions.api2())
}
}
Would call to api1() and api2() will be done in parallel or synchronously?And how can I do that parallely
- I would also like to mention that my application uses
redux-thunk
something like below but I am not exactly sure what this code is exactly doing. I have read https://redux.js.org/api-reference/applymiddleware that by applying middleware we can makedispatch
work asynchronously.
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import { createLogger } from 'redux-logger'
import axios from 'axios'
import { routerMiddleware } from 'react-router-redux'
import InitialState from './InitialState'
const middleware = [ thunk.withExtraArgument(axios), routerMiddleware(history) ]
/* eslint-enable no-undef */
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore(
rootReducer,
InitialState,
composeEnhancers(applyMiddleware(...middleware))
)
export default store