Skip to content

Instantly share code, notes, and snippets.

@edrpls
Created July 25, 2019 18:59
Show Gist options
  • Save edrpls/c526f22149f4ec69502412b59dad5249 to your computer and use it in GitHub Desktop.
Save edrpls/c526f22149f4ec69502412b59dad5249 to your computer and use it in GitHub Desktop.
// clientsReducer.js
// Set the initial state to be used
const initialState = {
clients: []
};
// define and export reducer
export default function clientsReducer(state = initialState, action) {
// handle action's results
switch (action.type) {
// Set the result of the async request to state
case 'GET_CLIENTS': {
return {
clients: action.clients
};
}
// Toggles the direction of the results
case 'TOGGLE_SORTING': {
return {
clients: state.clients.reverse()
};
}
// return the default state if no action was found
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment