Last active
October 8, 2018 18:13
-
-
Save productioncoder/a7381a3f3b41547117ae3c130374d2f8 to your computer and use it in GitHub Desktop.
Using Reselect in a Redux project
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
import {createSelector} from 'reselect'; | |
export default function (state = {}, action) { | |
switch (action.type) { | |
case UPDATE_FIRST_NAME: | |
return { | |
...state, | |
firstName: action.firstName | |
}; | |
case UPDATE_LAST_NAME: | |
return { | |
...state, | |
firstName: action.lastName | |
}; | |
default: | |
return state; | |
} | |
} | |
export const getFullName = createSelector( | |
(state) => state.firstName, | |
(state) => action.lastName, | |
(firstName, lastName) => [firstName,lastName].join(' ') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment