Skip to content

Instantly share code, notes, and snippets.

@Ayyagaries
Created April 17, 2018 05:04
Show Gist options
  • Save Ayyagaries/92c04adcb7aa6dad0b0ed30aecab96f8 to your computer and use it in GitHub Desktop.
Save Ayyagaries/92c04adcb7aa6dad0b0ed30aecab96f8 to your computer and use it in GitHub Desktop.
Reducer Code
import {
REQUEST_REP_SEARCH,
SUCCESS_REP_SEARCH,
RESET_DATA,
SHOW_ALERT,
} from '../actions/searchReps';
const intitalState = {
showLoading: false,
repsFound: [],
showAlert: false,
};
export default (state = intitalState, action) => {
switch (action.type) {
case SHOW_ALERT: {
return {
...state,
showLoading: false,
showAlert: true,
};
}
case RESET_DATA: {
return {
...state,
showLoading: false,
repsFound: [],
showAlert: false,
};
}
case REQUEST_REP_SEARCH: {
return {
...state,
repsFound: [],
showLoading: true,
showAlert: false,
};
}
case SUCCESS_REP_SEARCH:
return {
...state,
repsFound: action.repsFound,
showLoading: false,
showAlert: false,
};
default:
return state;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment