Skip to content

Instantly share code, notes, and snippets.

@indigoviolet
Created October 4, 2017 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indigoviolet/de78beb8f74dba36596fb826212bf6d1 to your computer and use it in GitHub Desktop.
Save indigoviolet/de78beb8f74dba36596fb826212bf6d1 to your computer and use it in GitHub Desktop.
fin blog embed
import { createAsyncAction, createAsyncReducer } from 'helpers/async';
// I'm using the fetch api here, but you can substitute any http request libarary.
// For more about the fetch api: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
const postsRequest = (subreddit) => {
return fetch(`https://www.reddit.com/r/${subreddit}.json`)
.then(
response => response.json(),
error => console.log('An error occured.', error)
)
}
const FETCH_POSTS = 'Actions/Posts/Fetch';
// async action
export const fetchPosts = createAsyncAction(FETCH_POSTS, postsRequest);
// async reducer with shape { loading, data, error }
export const posts = createAsyncReducer(FETCH_POSTS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment