MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Redux Toolkit Architecture and Slices0%
Study Materials
React.js for AdvancedProgress 0%
1.1Control Props and Inversion of Control Pattern1.2State Reducer Pattern in Advanced React1.3Prop Getters and Flexible Design Systems1.4Headless UI Architecture and Accessibility Primitives
2.1Redux Toolkit Architecture and Slices2.2RTK Query for Enterprise Data Fetching2.3Atomic State Management with Jotai and Recoil2.4Event-Driven State and Finite State Machines with XState
HomeTutorialsReact.js for AdvancedRedux Toolkit Architecture and Slices
RTK Query for Enterprise Data Fetching

Redux Toolkit Architecture and Slices

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. The Renaissance of Redux with Redux Toolkit (RTK)

Historically, Redux was infamous for overwhelming boilerplate: writing actions, action types, action creators, reducers with manual object spreads, and configuring stores with multiple middleware packages.

In 2019, the Redux team released Redux Toolkit (RTK)—the official, opinionated, battery-included standard for modern Redux development.

RTK simplifies Redux by:

  • Eliminating manual action creators and action types.
  • Incorporating Immer under the hood, allowing developers to write "mutating" logic that is automatically converted into safe immutable updates!
  • Including redux-thunk by default for asynchronous actions.
  • Providing configureStore with automated DevTools and middleware setup.
1Legacy Redux:
2ActionTypes ──► ActionCreators ──► Manual Switch Reducer with Object Spread ──► createStore()
3 
4Modern Redux Toolkit:
5createSlice({ name, initialState, reducers }) ──► configureStore({ reducer })
6(Clean, concise, and built-in Immer mutation syntax!)

2. Installation

1npm install @reduxjs/toolkit react-redux

3. Creating an RTK Slice (createSlice)

A Slice bundles a domain's initial state, reducer functions, and generated actions together into a single cohesive module:

1// src/store/courseSlice.js
2import { createSlice } from '@reduxjs/toolkit';
3 
4const initialState = {
5 enrolledCourses: [],
6 selectedTrack: 'all',
7 searchQuery: ''
8};
9 
10export const courseSlice = createSlice({
11 name: 'courses',
12 initialState,
13 reducers: {
14 // Immer allows us to write "mutating" syntax safely!
15 enrollCourse: (state, action) => {
16 const exists = state.enrolledCourses.some(c => c.id === action.payload.id);
17 if (!exists) {
18 state.enrolledCourses.push(action.payload); // Safe via Immer!
19 }
20 },
21 removeCourse: (state, action) => {
22 state.enrolledCourses = state.enrolledCourses.filter(c => c.id !== action.payload);
23 },
24 setSelectedTrack: (state, action) => {
25 state.selectedTrack = action.payload;
26 },
27 setSearchQuery: (state, action) => {
28 state.searchQuery = action.payload;
29 }
30 }
31});
32 
33// Automatically generated action creators!
34export const { enrollCourse, removeCourse, setSelectedTrack, setSearchQuery } = courseSlice.actions;
35 
36// Export reducer for store configuration
37export default courseSlice.reducer;

4. Configuring the Central Store (configureStore)

1// src/store/index.js
2import { configureStore } from '@reduxjs/toolkit';
3import courseReducer from './courseSlice';
4 
5export const store = configureStore({
6 reducer: {
7 courses: courseReducer
8 }
9});

Wrap your root in src/main.jsx:

1import { Provider } from 'react-redux';
2import { store } from './store';
3 
4<Provider store={store}>
5 <App />
6</Provider>

5. Consuming State with useSelector and useDispatch

1import React from 'react';
2import { useSelector, useDispatch } from 'react-redux';
3import { enrollCourse } from '../store/courseSlice';
4 
5export default function CourseCard({ course }) {
6 const dispatch = useDispatch();
7 
8 // Fine-grained selector: only re-renders if this specific boolean changes!
9 const isEnrolled = useSelector((state) =>
10 state.courses.enrolledCourses.some(c => c.id === course.id)
11 );
12 
13 return (
14 <div className="card">
15 <h4>{course.title}</h4>
16 <button
17 disabled={isEnrolled}
18 onClick={() => dispatch(enrollCourse(course))}
19 >
20 {isEnrolled ? 'Enrolled ✓' : 'Enroll Now'}
21 </button>
22 </div>
23 );
24}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How does Redux Toolkit (RTK) allow developers to write direct mutations like state.items.push(item) safely?
Question 2
What is an RTK "Slice"?
Question 3
Which hook is used to dispatch actions in React-Redux?
Question 4
Which hook is used to extract data from the Redux store with selector functions?
Question 5
What function replaces the legacy createStore in modern Redux Toolkit?
Next Lesson

RTK Query for Enterprise Data Fetching

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Headless UI Architecture and Accessibility PrimitivesRTK Query for Enterprise Data Fetching

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master React.js for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext