Created
November 3, 2019 16:05
-
-
Save santospatrick/5751e87f1a62b645829e31fafa7fb960 to your computer and use it in GitHub Desktop.
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
// Sagas | |
import { call, put } from 'redux-saga/effects' | |
import api from 'services/api' | |
export function* fetchUser(action) { | |
const { data } = yield call(api.get, `/user/${action.id}`) | |
yield put({ type: "@user/FETCH_SUCCEEDED", data }) | |
} | |
// Thunks | |
import api from 'services/api' | |
export function fetchUser(id) { | |
return dispatch => { | |
return api.get(`/user/${id}`) | |
.then(({ data }) => { | |
dispatch({ type: "@user/FETCH_SUCCEEDED", data }); | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment