Skip to content

Instantly share code, notes, and snippets.

@talkol
Created October 14, 2016 18:18
Show Gist options
  • Select an option

  • Save talkol/6b08bedbd35bcb530202483ff9a9c713 to your computer and use it in GitHub Desktop.

Select an option

Save talkol/6b08bedbd35bcb530202483ff9a9c713 to your computer and use it in GitHub Desktop.
import _ from 'lodash';
import * as types from './actionTypes';
import redditService from '../../services/reddit';
export function fetchTopics() {
return async(dispatch, getState) => {
try {
const subredditArray = await redditService.getDefaultSubreddits();
const topicsByUrl = _.keyBy(subredditArray, (subreddit) => subreddit.url);
dispatch({ type: types.TOPICS_FETCHED, topicsByUrl });
} catch (error) {
console.error(error);
}
};
}
@pedro-mass
Copy link
Copy Markdown

It allows us to use await in the body of the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment