Redux/Redux Toolkit Assignment – 2
Basic Questions
- Install Redux Toolkit in a React project using npm install @reduxjs/toolkit react-redux.
- Create and export a Redux store using configureStore().
- Compare configureStore() with vanilla createStore() in Redux.
- Add a counter reducer to the store.
- Log the store state before and after a dispatch.
- Create a slice named counterSlice with initial state {value: 0}.
- Add a reducer inside the slice for increment to increase value by 1.
- Add a reducer for decrement.
- Add a reducer for reset to reset count to 0.
- Export counterSlice.reducer and use it in configureStore().
- Dispatch increment() action from the slice and log the state.
- Dispatch decrement() action and log the state.
- Dispatch reset() and verify state reset.
- Create multiple reducers inside a single slice (e.g., incrementByAmount).
- Access generated action creators from the slice (counterSlice.actions).
- Enable Redux DevTools in configureStore.
- Write a dummy slice called themeSlice with states light and dark.
- Toggle theme using toggleTheme() reducer.
- Create a slice called authSlice with isLoggedIn: false.
- Write reducers login() and logout() in authSlice and test dispatch.
Intermediate Questions
- Create a slice that manages a list of todos (addTodo, removeTodo).
- Add a reducer that marks a todo as completed.
- Create a userSlice with name and email fields, and write reducers for updateName and updateEmail.
- Use counterSlice to increment by a dynamic payload value.
- Build a slice that manages notifications (addNotification, clearNotifications).
- Use immer (built into RTK) by updating nested state immutably.
- Combine multiple slices (counterSlice, userSlice) in the same store.
- Log dispatched action types from store.subscribe().
- Create an async thunk fetchUsers that fetches from https://jsonplaceholder.typicode.com/users.
- Add extraReducers to handle fetchUsers.pending.
- Add extraReducers to handle fetchUsers.fulfilled.
- Add extraReducers to handle fetchUsers.rejected.
- Track loading, success, and error states inside a usersSlice.
- Dispatch fetchUsers() and console.log state updates.
- Show loading spinner in UI when fetchUsers is pending.
- Display error message in UI if fetchUsers is rejected.
- Create a productsSlice that fetches products from a fake API using createAsyncThunk.
- Build cartSlice to add, remove, and clear items.
- Display total cart quantity in a component.
- Use Redux DevTools to inspect async actions step by step.
Advanced Questions
- Create a postsSlice with fetchPosts async thunk from an API.
- Handle loading, error, and success states with clear UI indicators.
- Add addNewPost async thunk to create a new post on the server.
- Chain multiple thunks → fetch users, then fetch posts by a specific user.
- Write a middleware-like slice that logs when any async action is pending.
- Show difference between Redux Thunk and createAsyncThunk with example code.
- Build a mini blog app with postsSlice and usersSlice, fetching and displaying from API.
- Implement a login system using authSlice + async API call (loginUser).
- Create an e-commerce app slice structure (products, cart, orders), each using async thunks.
- Develop a dashboard that loads multiple API endpoints (stats, users, notifications) using createAsyncThunk.