Skip to content

Instantly share code, notes, and snippets.

@jamesseanwright
Created December 21, 2018 17:29
Show Gist options
  • Select an option

  • Save jamesseanwright/430d183150efcbe826e30a3929746e98 to your computer and use it in GitHub Desktop.

Select an option

Save jamesseanwright/430d183150efcbe826e30a3929746e98 to your computer and use it in GitHub Desktop.
Redux Thunk Example
export const addRonSwansonQuote = () =>
(dispatch: React.Dispatch<Action>) => {
dispatch(setQuoteLoading());
return fetch('https://ron-swanson-quotes.herokuapp.com/v2/quotes')
.then(res => res.json())
.then(([quote]: string[]) =>
dispatch(addMessage(quote)),
)
.catch(() => dispatch(setQuoteError()));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment