score:1
Accepted answer
you should have a look at the documentation: promise.all()
promise.all()
actually preserves the order for its returned values.
hence you could have:
const promises = [];
promises.push(fetch("http://localhost:7890/1.1/statuses/user_timeline.json?count =30&screen_name=techcrunch"));
promises.push(fetch("http://localhost:7890/1.1/statuses/user_timeline.json?count=30&screen_name=laughingsquid"));
promises.push(fetch("http://localhost:7890/1.1/statuses/user_timeline.json?count=30&screen_name=appdirect"));
// execute all promises
promise.all(promises).then(values => {
console.log(values);
const twitterfeed = { ...this.state.twitterfeed};
twitterfeed.techcrunch = json.parse(values[0]);
twitterfeed.laughingsquid = json.parse(values[1]);
twitterfeed.appdirect = json.parse(values[2]);
this.setstate({
isloadcomplete: true,
twitterfeed
});
});
score:1
if you are familiar with the axios library.you can use there axios.all([]) calling method. as mentioned in there docs :
function a() {
return axios.get(url,[config]);
}
function b() {
return axios.get(url,[config]);
}
axios.all([a(), b()])
.then(axios.spread(function (result_a, result_b) {
// both requests are now complete and you can setsate here.
}));
github : https://github.com/axios/axios
score:1
var promise1 = fetch("http://localhost:7890/1.1/statuses/user_timeline.json?count =30&screen_name=techcrunch");
var promise2 = fetch("http://localhost:7890/1.1/statuses/user_timeline.json?count=30&screen_name=laughingsquid");
var promise3 =fetch("http://localhost:7890/1.1/statuses/user_timeline.json?count=30&screen_name=appdirect");
promise.all([promise1, promise2, promise3]).then(function(values) {
console.log(values);
});
//you can now extend it as you want
Source: stackoverflow.com
Related Query
- Set React array state after promise all is completed
- How to return value after all promise in React and Firebase?
- How can I reset a react component including all transitively reachable state?
- How to pass all other props to react class?
- How can I block a React component to be rendered until I fetched all informations?
- Promise Error: Objects are not valid as a React child
- Does this.setState return promise in react
- Apply style "cursor: pointer" to all React components with onClick function
- React Router: get all routes as array
- get promise value in react component
- React native flex box not using all available space
- React - How to detect when all sub-components of a parent component are visible to the user?
- Accessing object in returned promise using fetch w/ react js
- React Route Component handle all "/" routes EXCEPT for "/login"
- react / redux-form: how to return promise from onSubmit?
- Where to put all the screens which are common in multiple stack navigators? - React Navigation v5
- Using react i18next on all nested components
- React Native FlatList horizontal mode not working at all
- how to get list of all registered synthetic event handlers/listeners for a React Component?
- React Native - Return all JSON data in AsyncStorage?
- Select all and Select None buttons in Autocomplete Material UI React
- create react app : configure Jest : Run all test files
- React Router: Update only one query parameter instead of replacing all
- How do I target DOM elements inside a react component, or should I avoid targeting DOM elements all together?
- React does not rerender after setState used in promise
- React - load all data from json into component
- How to redirect all request to index in react or angular using htaccess?
- React input checkbox select all component
- React Developer Tools shows all components as "Anonymous"
- React Context Provider all children re rendering
More Query from same tag
- How to map through an Array of object with the same data on some object and get it displayed once and also get other properties
- How do I ensure context is updating properly for every component in ReactJS?
- passing data from child to parent component - react - via callback function
- How to properly set the background of Container or other MUI Components?
- I am having trouble with dispatching redux action from react Login component . I have tried to figure it out in vain
- How to set crop parameters to original image in React?
- Type '{}' is not assignable to type 'ReactNode'
- Arrow functions not working in browser
- Updating state from child component to parent component
- How do I convert the firestore data to a JSON object?
- React - Filter list by gender or age
- How to enable babel stage-0 in webpack config file
- npm test -- --coverage never exits
- Antd steps component creating single instance instead of proper steps
- async inside useEffect react
- How to set a css property (background-color) dynamically in React?
- pass value of clicked list to EditForm to edit
- React component initialize state from props
- React React setState not updating on First attempt
- spinner for each component in react
- How to get onClick Event for a Label in ChartJS and React?
- Fail to send data back to React
- React shouldComponentUpdate() does not prevent re-render
- React Context vs Javascript window
- JavaScript array comparisions and display values from another
- How to check if profile images exist else use fallback jpg in a react App
- Remove Unused JS/CSS bundles Code Splitting Webpack
- Value of this in React event handler
- Use React Js to create Desktop like menu in AngularJs
- onClick Event return Proxy object instead of event handler object in ReactJX