Created
February 18, 2017 18:39
-
-
Save dabit3/ff77d97b35667411e0ef16c802219ac0 to your computer and use it in GitHub Desktop.
Medium - redux4ways - dataReducer.js
This file contains hidden or 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 { FETCHING_DATA, FETCHING_DATA_SUCCESS, FETCHING_DATA_FAILURE } from '../constants' | |
const initialState = { | |
data: [], | |
dataFetched: false, | |
isFetching: false, | |
error: false | |
} | |
export default function dataReducer (state = initialState, action) { | |
switch (action.type) { | |
case FETCHING_DATA: | |
return { | |
...state, | |
data: [], | |
isFetching: true | |
} | |
case FETCHING_DATA_SUCCESS: | |
return { | |
...state, | |
isFetching: false, | |
data: action.data | |
} | |
case FETCHING_DATA_FAILURE: | |
return { | |
...state, | |
isFetching: false, | |
error: true | |
} | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment