axios.all() after response send a new request
See original GitHub issueHow can i send a new request using axios until axios.all() response has not come. I have three type of request need to load when app is load first time. After response of each api i want to send a new request using these api response data.
Here is my code that return network error 500
export function appInitialize(navigator) {
return async function (dispatch) {
dispatch({ type: APP_INITIALIZE });
axios.all([
api.get('appload'),
api.get('admin-settings'),
axios.get('https://example.com/api/ipinfo')
]).then(axios.spread((appLoadRes, adminSettingsRes, ipRes) => {
dispatch({
type: APP_INITIALIZED,
payload: {
appload: appLoadRes.data.response.data,
adminSettings: adminSettingsRes.data.response.data,
ip: ipRes.data.ip
}
});
dispatch(changeAppRoot('after-login'));
getUser().then(user => {
if (user) {
dispatch(changeAppRoot('after-login'));
api.get(`user/${user.id}`, {
headers: {
'Authorization': `Bearer ${user.token}`,
'Ip': ipRes.data.ip
}
}).then(response => {
dispatch({ type: USER_MANAGED, payload: response.data })
})
navigator.resetTo({
screen: 'navigation.Dashboard'
})
} else {
navigator.resetTo({
screen: 'navigation.Login'
})
}
})
}))
};
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Using axios.all to make concurrent requests - LogRocket Blog
The axios.all function accepts an iterable object that must be a promise, such as a JavaScript array, and it returns an array of...
Read more >How to send multiple requests using axios - Storyblok
Let us start with a small task and sending one request using Axios itself. First, we import axios and define the API/URL we...
Read more >How to Perform HTTP Requests with Axios – A Complete Guide
Axios allows us to send multiple requests at the same time. To do so, we'll use the Promise.all() function in this tutorial to...
Read more >Making HTTP requests with Axios - CircleCI
Axios works by making HTTP requests with NodeJS and XMLHttpRequests on the browser. If the request was successful, you will receive a response...
Read more >Make Multiple Post Requests In Axios then get all the ...
I made a very simplified example of what you're trying to accomplish using async/await syntax since .then() would be messier to read; ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey there @shubham81407,
You could try something like this;
What do you think?
For these kind of general question, please consider asking on StackOverflow. But feel free to come back and open an issue if it turns out to be a bug.