Created
December 22, 2018 17:40
-
-
Save jamesseanwright/0c4f3cb092b7e3241c9f32ec49cef5d1 to your computer and use it in GitHub Desktop.
Example Reducer
This file contains hidden or 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
| const rootReducer: React.Reducer<State, Action> = (state, action) => { | |
| if (isAddMessage(action)) { | |
| const { message } = action.payload; | |
| return { | |
| ...state, | |
| isLoadingQuote: false, | |
| hasQuoteError: false, | |
| isFormValid: !!message, | |
| messages: [ | |
| ...(message ? [message] : []), | |
| ...state.messages, | |
| ], | |
| }; | |
| } | |
| if (isSetQuoteLoading(action)) { | |
| return { | |
| ...state, | |
| isLoadingQuote: true, | |
| hasQuoteError: false, | |
| }; | |
| } | |
| if (isSetQuoteError(action)) { | |
| return { | |
| ...state, | |
| isLoadingQuote: false, | |
| hasQuoteError: true, | |
| }; | |
| } | |
| return state; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment