Skip to content

Instantly share code, notes, and snippets.

@jtulk
Created July 13, 2017 06:47
Show Gist options
  • Save jtulk/27f2c30a053a075d67c2d18e5ad3e8a4 to your computer and use it in GitHub Desktop.
Save jtulk/27f2c30a053a075d67c2d18e5ad3e8a4 to your computer and use it in GitHub Desktop.
import { ACTIONS } from './actions';
const initialState = {
content: {},
error: null,
isFetching: false,
lastFetched: 0
}
const myContentReducer = (state = initialState, action = {}) => {
const { error, payload, type } = action;
switch (type) {
case ACTIONS.error: {
return {
...state,
error,
isFetching: false
};
}
case ACTIONS.startFetch: {
return {
...state,
isFetching: true
};
}
case ACTIONS.update: {
return {
...state,
content: payload,
error: null,
isFetching: false,
lastFetched: Date.now()
};
}
default: {
return state;
}
}
};
export default myContentReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment