Skip to content

Instantly share code, notes, and snippets.

@santospatrick
Created November 3, 2019 16:05
Show Gist options
  • Save santospatrick/5751e87f1a62b645829e31fafa7fb960 to your computer and use it in GitHub Desktop.
Save santospatrick/5751e87f1a62b645829e31fafa7fb960 to your computer and use it in GitHub Desktop.
// 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