What is Redux-Saga and how does it differ from Thunks?

Answer

Redux-Saga is a middleware library for handling complex async side effects using ES6 generators. Sagas are long-running background tasks that watch for actions and respond. Define a saga: function* fetchUserSaga(action) { try { const user = yield call(api.getUser, action.payload); yield put(userLoaded(user)); } catch (error) { yield put(loadingFailed(error.message)); } } function* watchFetchUser() { yield takeEvery("users/fetchRequested", fetchUserSaga); }. Key effects: call: call a function (async). put: dispatch an action. takeEvery: listen for actions. takeLatest: cancel previous, handle only latest. all: run effects in parallel. race: cancel others when first completes. Sagas vs Thunks: Thunks are simple functions — easy to write, hard to test complex flows. Sagas are testable (generators return effect descriptors, not actual API calls) and excellent for complex flows (retry, cancellation, race conditions, debouncing). Sagas are harder to learn but more powerful for complex async orchestration. For simple API calls, use createAsyncThunk. For complex workflows with cancellation/retry, use Sagas.