-
-
Save edrpls/c526f22149f4ec69502412b59dad5249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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