I've looked at several questions on using async/await with a forEach loop but nothing seems to cover my user case... How can I get the code below to work? Right now I'm getting the following error:
await is a reserved word
Here's the code:
export const fetchUserBookmarks = ( bookmarksIDs ) => async ( dispatch, getState, api ) => {
dispatch({
type: 'IS_FETCHING_BOOKMARKS'
});
try {
bookmarks = [];
bookmarksIDs.forEach( bookmarkID => {
const bookmark = await api.get( selectedPostByIdEP + bookmarkID );
bookmarks.push( bookmark );
});
dispatch({
type: 'HAS_FETCHED_BOOKMARKS',
payload: bookmarks
});
} catch( error ) {
dispatch({
type: 'FAILED_FETCHING_BOOKMARKS',
payload: error
});
}
}