Skip to main content
Practice Problems

Redux Thunk vs Redux Saga - what is the difference?

Both handle async in Redux differently.

Redux Thunk

Simple: dispatch functions.

```javascript // Action creator returns function const fetchUser = (id) => async (dispatch) => { dispatch({ type: 'FETCH_USER_REQUEST' });

try { const user = await api.getUser(id); dispatch({ type: 'FETCH_USER_SUCCESS', payload: user }); } catch (error) { dispatch({ type: 'FETCH_USER_FAILURE', error }); } };

// Usage dispatch(fetchUser(123)); ```

Redux Saga

Powerful: generator functions.

```javascript import { call, put, takeLatest } from 'redux-saga/effects';

function* fetchUser(action) { try { const user = yield call(api.getUser, action.payload); yield put({ type: 'FETCH_USER_SUCCESS', payload: user }); } catch (error) { yield put({ type: 'FETCH_USER_FAILURE', error }); } }

function* watchFetchUser() { yield takeLatest('FETCH_USER_REQUEST', fetchUser); } ```

Comparison

FeatureThunkSaga
Learning curveEasySteep
Async handlingPromisesGenerators
CancellationHardBuilt-in
TestingHarderEasier
DebouncingManualBuilt-in
Best forSimpleComplex

When Use What

Thunk: Simple API calls Saga: Complex workflows

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems