Reputation: 1341
I have this deleteSkill handler. In this handler I'm calling some api to delete skill. ( yield call(utils.deleteSkill) ). Its calling the api successfully but after that nothing execute. The console statement after yield call doesn't output anything. I'm not able to figure out anything. Can anyone help me please?
import { takeLatest, delay, takeEvery } from 'redux-saga'
import { call, fork, put, race, take } from 'redux-saga/effects'
import * as ActionTypes from './../constants/actions'
/* Handlers */
function* fetchSkills(action) {
try {
const { data } = yield call(utils.fetchSkills, action)
yield put({type: ActionTypes.SUCCESS_FETCH_SKILLS, data})
} catch (e) {
}
}
function* deleteSkill(action) {
try {
yield call(utils.deleteSkill, action.data) //doesn't execute after this
console.log('Hello') //won't execute
yield put({type: ActionTypes.REQUEST_FETCH_SKILLS})
} catch (e) {}
}
/* Watchers */
function* watchFetchSkills() {
while (true) {
yield* takeLatest(ActionTypes.REQUEST_FETCH_SKILLS, fetchSkills)
}
}
function* watchDeleteSkill() {
while (true) {
yield* takeLatest(ActionTypes.REQUEST_DELETE_SKILL, deleteSkill)
}
}
export default function* rootSaga() {
yield [
fork(watchFetchSkills),
fork(watchDeleteSkill),
]
}
Upvotes: 2
Views: 2230
Reputation: 1
de-structuring 'action' and passing only required arguments to "yield call(actionFunc, ...args)" might help.
Upvotes: 0
Reputation: 808
I suspect that it's because in your function* watchFetchSkills()
and function* watchDeleteSkill()
, the yield
should not have an *
. It should just be yield
.
Even though you're calling another generator function from
function* watchDeleteSkill()
it's actually calling takeLatest
, which according to the source:
Is not a generator function. It's just a plain old function, which means yield*
isn't needed.
Upvotes: 1