Skip to content

Instantly share code, notes, and snippets.

@andrewzey
Last active April 17, 2017 21:16
Show Gist options
  • Save andrewzey/d9c18321a4b3a9f7af375ac69534bb39 to your computer and use it in GitHub Desktop.
Save andrewzey/d9c18321a4b3a9f7af375ac69534bb39 to your computer and use it in GitHub Desktop.
Redux Thunk with FSA Actions
// Without depending on forks of redux-thunk, here's
// how we would handle FSA actions created with redux-actions
// using redux-thunk middleware:
import { createAction } from 'redux-actions';
const loginRequest = username => dispatch => {
dispatch(createAction('LOGIN_REQUEST')());
return request('/login', { username })
.then(resp => dispatch(loginSucess(resp)))
.catch(err => dispatch(loginFailure(err)));
};
const loginSuccess = createAction('LOGIN_SUCCESS', resp => resp.body);
const loginFailure = createAction('LOGIN_FAILURE', err => err);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment