Redux/Redux Toolkit Assignment – 6
Basic Questions
- Identify and fix an anti-pattern: Mutating state directly inside a reducer.
- Practice replacing useSelector() that returns the entire state with a selector for only required slice.
- Avoid inline anonymous functions in mapDispatchToProps → refactor to action creators.
- Fix an anti-pattern: Storing a whole API response object in Redux vs storing only normalized data.
- Demonstrate why you shouldn’t duplicate the same data in two slices.
- Avoid side effects (like API calls) directly inside reducers.
- Replace constants + manual action types with RTK slice auto-generated actions.
- Create an RTK Query endpoint to fetch a list of users.
- Use useAddUserMutation() to submit a new user to the backend.
- Connect a frontend Redux cartSlice with a backend cart API.
- Ensure server-side state (getPosts) syncs with cache using invalidateTags.
- Handle errors from the backend gracefully in UI (isError + error.message).
- Write a unit test for a counterSlice reducer increment.
- Write a unit test for decrement action.
- Test that unknown action returns the current state in reducer.
- Test a Redux action creator returns the correct type + payload.
- Mock a simple RTK Query endpoint response using msw or manual mock.
- Compare rendering behavior with useSelector(state => state) vs selective property.
- Wrap a todo list component with React.memo and show fewer re-renders.
- Demonstrate useMemo to memoize an expensive calculation based on Redux state.
Intermediate Questions
- Refactor a reducer that mutates nested objects into an immutable approach with immer.
- Convert a slice storing duplicated posts and comments into normalized entities using createEntityAdapter.
- Demonstrate why calling API requests inside useEffect+dispatch is an anti-pattern → replace with RTK Query.
- Refactor a state shape with redundancy into minimal + normalized state.
- Use selectors to extract data instead of mapping entire slice in every component.
- Show side-effect anti-pattern (API call inside reducer) and fix with createAsyncThunk.
- Connect Redux auth state with backend API for login/logout via RTK Query mutation.
- Add token-based authentication: Save access token in Redux, sync refresh logic from API.
- Implement a product list UI using RTK Query (useGetProductsQuery).
- Update an item stock with useUpdateProductMutation.
- Sync local cart items Redux slice with backend database after checkout.
- Build optimistic UI update for deleting a comment, rollback if API fails.
- Test multiple reducers combined using configureStore.
- Mock a backend API with msw (Mock Service Worker) for RTK Query.
- Write a test that ensures caching prevents duplicate API calls.
- Test loading/error states from a useGetUsersQuery hook using React Testing Library.
- Unit test an async thunk with mocked API (fulfilled & rejected cases).
- Create a memoized selector using createSelector for filtering todos.
- Use useCallback for passing stable callbacks to child components connected to Redux.
- Identify and prevent unnecessary component re-renders with profiler before & after optimization.
Advanced Questions
- Audit a Redux project for anti-patterns: (duplicate state, API calls in reducers, overly large states). Fix each problem with RTK best practices.
- Refactor a project that directly stores full API responses into normalized slices with createEntityAdapter.
- Identify performance pitfalls in selectors (returning new object each call), optimize with createSelector.
- Build a full CRUD posts module with getPosts, addPost, updatePost, deletePost synced to backend API.
- Implement JWT authentication flow (login, token storage, protected queries/mutations).
- Combine local client slice (uiSlice) with server-state slice (apiSlice) in one scalable store.
- Write end-to-end tests for an RTK Query-based feature with mock API responses.
- Build a scalable test suite: unit test reducers, action creators, thunks, and RTK Query hooks.
- Optimize a large list rendering with React.memo, useMemo, and cache selectors → measure with React Profiler.
- Migrate a large Redux project using bad patterns into best practice state architecture with normalized slices, API integration, and full test coverage.