score:3
Accepted answer
use promise.all to get a single promise that resolves with an array of values once every promise in the array has resolved:
const storypromises = ids.data.map(id => {
return axios.get(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
});
const stories = await promise.all( storypromises );
this.setstate({ data: stories });
Source: stackoverflow.com
Related Query
- Assign value of returned promises with .map
- React with TypeScript - map an array of promises returned inside a for loop
- setState with value of previously returned custom hook
- How to assign a value to state and use setState in ReactJs with Typescript
- Is it possible to assign promise data value to outside variable with react.js
- JavaScript Map Function with React.js gives me index, but not value in the index
- React how to use setState with Map value
- How to make multiple axios.get() requests with componentDidMount() and assign a response value of the 1st to the 2nd?
- React hook form how to pass value from custom component to controller with already assign own on change?
- An array of promises is returned when using axios in map function?
- Dynamically set defaultChecked with value of setState within data map with react hooks
- ReactJS: Join map output with concatenating value
- How to use a state value with map function to display repeat ui in react component
- Why am I getting "undefined" even though there is a value being returned in React with Firebase Realtime DB?
- How to map with unique value in pattern
- Unable to update a list with react when its value is being changed using the hook useState function from React TypeError: map is not a function
- React, state update function from map with target name and value
- How to assign a value to the state with a promise prior to the render method executing
- How to assign a value returned by jQuery AJAX call to a class variable?
- how to correctly map an obj and return a single value with several identical values ReactJS
- how to get the value of a map returned button in react
- Creating functions in react with d3 to assign colors to value
- Reactjs select value opition value map iteration with default value
- React get returned value from function with fetch
- How to use map on json response returned by a REST API with ReactJs
- How to correctly use a value returned by a promise and map through it
- Testing returned value of component method with value passed through
- Cannot mock returned value of react hook with different values for each unittest
- How to assign arrays student's id with Boolean value in react js and if i clicked on button again back to boolean value for that particular student
- React leaflet too much refresh map with context update value
More Query from same tag
- Is there a better way to put classes into html and body tags in next.js?
- React Babel polyfill for Object.values()
- How to display Material UI drawer with top margin
- Refresh problem with onChange event handler
- Using sweet alert 2 getting this.props is undefined after using Warning alert
- React - Cannot dispatch onChange event from input text element programatically
- React Component TypeError Issue
- Reactjs map returns unexpected token }
- Passing function through Switch Route component
- Get options from multiple select form in React
- Custom hook stuck in recursive loop
- How to change a variable in the component view inside the callback function of $.ajax
- onClick inside mapped object JSX for React NextJS not working
- React-notification-system - trigger notification on JSON input
- Create temp file and get file with axios in React and show download pop up
- React build select input using for loop
- Vue js for non SPA apps - loading components in with out the app component
- How to print an array of object from highest to lowest value
- Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 | MongoDB > Express > React.js
- React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
- how to call function with parameter in JSX?
- async outside of componentDidMount in react
- Why isn't .env.development working in my Next.js app?
- React Context Provide not passing the value to the Consumer
- Cells overlapping problems in react virtualized with cell measurer
- simulate("click") in test of ejected react-create-app project doesn't cause rerender
- Use JSON database with Node & React
- Reactjs code/naming conventions
- How to use reduxForm() and connect() together for class component in react?
- redux state is undefined in useEffect and useSelector