Is there any way to detect when a saga has started? I'm looking for a way to add a loading dialog for all async requests such that when a saga starts, the loading dialog displays and when it is finished the loading dialog stops.
Right now I'm placing yield put(actions.setLoading(true)) at the top of every saga which seems less than ideal.
Each saga effect actually emit events. For more details look in sagaMonitor implementation.
You can also simply create a saga to encapsulate the full logic
function* wrapSaga(saga, ...args) {
yield put(setLoading(true))
try {
return yield call(saga, ...args)
} finally {
yield put(setLoading(false))
}
}
// used with fork
yield fork(wrapSaga, myAsyncTask, somearg)
I ended up going with @yelouafi suggestion, thanks!
Most helpful comment
You can also simply create a saga to encapsulate the full logic