Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 16, 2020 10:01
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 velotiotech/f9958986d542fbfece03896363de7719 to your computer and use it in GitHub Desktop.
Save velotiotech/f9958986d542fbfece03896363de7719 to your computer and use it in GitHub Desktop.
import {
GET_POSTS_BY_ID_REQUEST,
GET_POSTS_BY_ID_SUCCESS,
GET_POSTS_BY_ID_FAIL,
GET_POSTS_BULK_REQUEST,
GET_POSTS_BULK_SUCCESS,
GET_POSTS_BULK_FAIL
} from "./constants";
const reducer = (state, action) => {
switch (action.type) {
case GET_POSTS_BY_ID_REQUEST:
return {
...state,
byId: {
isLoading: true,
error: null,
data: null
}
}
case GET_POSTS_BY_ID_SUCCESS:
return {
...state,
byId: {
isLoading: false,
error: false,
data: action.payload
}
}
case GET_POSTS_BY_ID_FAIL:
return {
...state,
byId: {
isLoading: false,
error: action.payload,
data: false
}
}
case GET_POSTS_BULK_REQUEST:
return {
...state,
byBulk: {
isLoading: true,
error: null,
data: null
}
}
case GET_POSTS_BULK_SUCCESS:
return {
...state,
byBulk: {
isLoading: false,
error: false,
data: action.payload
}
}
case GET_POSTS_BULK_FAIL:
return {
...state,
byBulk: {
isLoading: false,
error: action.payload,
data: false
}
}
default: return state;
}
}
export default reducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment