In Redux Toolkit, the useSelector and useDispatch hook from React-Redux allows you to read data and dispatch actions of a specific slice of the Redux store inside a React component.
Import the useSelector or useDispatch hook from react-redux.
Use it inside your component to access the slice’s state or dispatch from event handlers and functions.
Reference the slice key you defined in configureStore() (e.g., state.counter.value, dipatch(increment())).
You're trying to display a user's name from the auth slice in a component, but it keeps re-rendering even when the name hasn't changed. How would you fix that?
Your component is breaking because useSelector is returning undefined. What are two common reasons this could happen when accessing a slice?
A feature shows a list of orders and their total prices, but the UI lags when scrolling. You suspect the selector is recalculating too often. How would you investigate and fix it?
A teammate says their component isn't updating when the cart slice changes. You check the selector and see it's returning a new array every time. What’s likely wrong, and how do you fix it?
You're optimizing a dashboard with 10+ components reading from the same large state slice. How would you structure your selectors to minimize re-renders and avoid memory bloat?
A legacy feature uses deeply nested state, and selectors are becoming unmaintainable. How would you refactor this to improve performance and testability without breaking existing components?
We're migrating from Redux to RTK Query, but several components still rely on manual useSelector calls to legacy slices. How do you plan the deprecation strategy while ensuring zero regressions?
A cross-team feature shares a state slice across three micro-frontends. How would you design the state structure and selector layer to avoid coupling, enable independent deployments, and maintain performance at scale?