What is Redux Thunk?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Redux / State Management topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

Redux Thunk is a middleware that allows dispatching functions (instead of just action objects) — enabling async operations in Redux. A thunk is a function that returns another function: const fetchUser = (id) => async (dispatch) => { dispatch(loadingStarted()); try { const user = await api.getUser(id); dispatch(userLoaded(user)); } catch (err) { dispatch(loadingFailed(err.message)); } }. Dispatch: dispatch(fetchUser(42)). Thunk middleware intercepts the function, calls it with dispatch and getState. With RTK's createAsyncThunk, the boilerplate is reduced: const fetchUser = createAsyncThunk("users/fetchById", async (id) => { return await api.getUser(id); }). RTK auto-generates fetchUser.pending, fetchUser.fulfilled, and fetchUser.rejected action types. Handle in slice: extraReducers: (builder) => builder.addCase(fetchUser.fulfilled, (state, action) => { state.user = action.payload; }).

Pro Tip

This topic has Redux / State Management-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.