score:0
Accepted answer
the problem is here:
headers.map((conversation) =>
conversation.conversators.filter(async (conversator) => {
if (conversator !== user._id) {
let conv = await getuserbyid(conversator);
fetchedconversations.push(conv);
}
})
);
you are pushing after awaiting a promise, but let the code continue on.
try this:
await promise.all(headers.map((conversation) =>
promise.all(conversation.conversators.filter(conversator=>conversator !== user._id)
.map(async (conversator) => {
let conv = await getuserbyid(conversator);
fetchedconversations.push(conv);
}));
));
map returns the promises, then you use promise.all to make them all into one promise and await it. there certainly is a better way to turn this out, but that should be enough to get you to understand what's happening.
Source: stackoverflow.com
Related Query
- Array is empty but not anymore when opened
- Formik testing error: The `document` global was defined when React was initialized, but is not defined anymore
- HTML5 video not loading in chrome, but works when the developer console is opened up
- React updating when array filters but not when an element is added
- How can I make useEffect not return the initial value? I keep getting empty array when I'm trying to pass an array of objects into a component
- array object working if we hardcode data but not working when we populate data from Node js to react js
- Data from API call are stored in a Array but when i try to use that array in a function for further use it shows that array is empty . why?
- React - using Context to pass down array variable, but when there is an update, component receiving array variable not re-render
- My array is not empty but array.length returns 0
- List not rendering even when the array is not empty and the state is not null
- I GET array from API but when i try show it in the table it show me empty array (noob ReactJs)
- this.setState not updating nested array in user object, but when console.loging the same logic, it returns a correct looking object
- react-redux not updating state when the API returns an empty array []
- I am trying to connect Lottery Contract to React Application using Metamask, But when I call manager() method on the contract I get an empty array
- Mapping through a fetched array from firebase but nothing shows up even though the array is not empty
- my images array is empty when I pass student to actions in redux but it is working in postman
- Getting an error "A non-serializable value was detected in the state" when using redux toolkit - but NOT with normal redux
- Object is not extensible error when creating new attribute for array of objects
- React useEffect Hook when only one of the effect's deps changes, but not the others
- React Router work on reload, but not when clicking on a link
- Dealing with an empty array when using .map() in React
- react material ui not responsive when opened in mobile browser
- Select, OutlineInput label with shrink property not same as TextField when empty
- JSDoc does not work in local package in a Lerna monorepo project using webpack dev server but works when released to package registry
- useEffect array dependency is called in every render when array is not changed
- React JS Fetch Returns Empty Response but Postman Does Not
- React: useCallback - useCallback with empty dependency array VS not using useCallback at all
- MobX not updating React view when pushing to an array
- React map not rendering array but console.logs
- My link to manifest.json in index.html works when I run react script 'yarn start', but not when I run 'python3 manage.py runserver'
More Query from same tag
- Open modal with ReactJS (es6) and siblings components
- Push state of reactive value to dependencies
- How do I add borderTop to React Material UI Table?
- fundamental redux concept- how to actions launch reducers
- Why isn't the length of my array being defined?
- Add pseudo-element on Material UI BottomNavigationAction
- React + Electron webview tag preload js not working
- How to save and remove value in useState using onClick in React?
- Why IndexOf(Object) in the redux case of React App is work?
- How to update React UI from with state in Redux store with useEffect
- React useEffect and componentWillUnmount with Redux
- What prop type should I check for requiring the source?
- react application not rendering react component in Express
- Reactjs - Why can't i set state?
- Identifying component from multiple components
- Is it safe to store JWT token in redux store?
- i18next not loading in file from public folder
- How to pass a file data in JSON payload to restful API
- Axios - Different headers for Express Request
- Issue using multiple styles with Material-ui and Radium
- React onClick event
- Environment variables: Heroku -> Docker -> Nginx -> React
- React - redirect and render component with props with react router
- Redux saga never runs
- Why does useParams during test return undefined in test env with wrapper?
- How can i pass useState value from child to parent
- how to align a grid item center in material-ui in react?
- Javascript compare two complex objects
- How to create moving text from right to left using react-spring?
- React router: going direcly to child path is not working