Skip to content

Instantly share code, notes, and snippets.

@rizedr
Created January 21, 2017 12:52
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 rizedr/b698649a9bef5842ff420a38553f4fda to your computer and use it in GitHub Desktop.
Save rizedr/b698649a9bef5842ff420a38553f4fda to your computer and use it in GitHub Desktop.
Store Reducer
import * as types from 'constants/products';
const initialState = {
items: [],
loading: false,
error: null,
};
export default function products(state = initialState, action) {
switch (action.type) {
case types.LOAD:
return {
...initialState,
loading: true,
};
case types.LOAD_SUCCESS:
return {
...state,
items: action.items,
loading: false,
};
case types.LOAD_FAIL:
return {
...state,
error: action.error,
loading: false,
};
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment