Skip to content

Instantly share code, notes, and snippets.

@jamesseanwright
Created December 22, 2018 17:40
Show Gist options
  • Select an option

  • Save jamesseanwright/0c4f3cb092b7e3241c9f32ec49cef5d1 to your computer and use it in GitHub Desktop.

Select an option

Save jamesseanwright/0c4f3cb092b7e3241c9f32ec49cef5d1 to your computer and use it in GitHub Desktop.
Example Reducer
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