-
-
Save indigoviolet/de78beb8f74dba36596fb826212bf6d1 to your computer and use it in GitHub Desktop.
fin blog embed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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