인프런 커뮤니티 질문&답변
api 호출할 때 call 질문입니다.
작성
·
188
0
saga에서 api호출 할 때
알려주신 방식과
function api(data) {
return axios.get(http...);
}
function* addPost(action) {
try {
const result = yield call(api , action.data)
}
**************************
다른 클래스에 api 호출하는 곳만 담아줘서
호출하는 방식이 있는데요
이렇게 되면 call 안쓰고 실행하게 됩니다.
이 두개의 차이점이 있나요?
import ItemService from '../../service/item/Item.service'
function* addItem(action) {
try {
const result = yield PostService.addItemApi(action.data)
yield put({
type: ADD_ITEM_SUCCESS,
data: result.data
})
} catch (err) {
yield put({
type: ADD_ITEM_FAILURE,
error : err.response.data
})
}
}




