InterviewHubPRO
Section Overview
Q337

Question 337 of 445

Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)

76%
React & Modern Frontend (445 Qs)•Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)

What happens when you dispatch an action?

  1. store.dispatch(action) is called with a plain action object ({ type, payload }).
  2. The action passes through the middleware chain in order (e.g., logger → thunk → your custom middleware); async/thunk middleware may intercept it here (e.g., a thunk function is invoked instead of being forwarded, or a Promise/generator is handled) or asynchronous side-effects can trigger further dispatches later.
  3. Once every middleware calls next(action), the action reaches the root reducer.
  4. The root reducer (usually built with combineReducers or RTK's configureStore) forwards the action to every slice reducer, each returning either its unchanged state or a new state object.
  5. The store replaces its internal state tree with the combined result and marks the update complete.
  6. The store notifies all subscribers (React-Redux's Provider/useSelector internals) that state changed.
  7. Each connected component's selector is re-run and compared (via === or a custom equality function) against its previous result; components only re-render if their selected slice actually changed.

Practical Code Example

text
// Action Dispatch Cycle:
// dispatch(action) -> Middlewares intercept -> Reducer calculates nextState ->
// Store updates -> Subscribed selectors notify components -> Components re-render