createSlice() is a function provided by Redux Toolkit that simplifies creating Redux logic for a specific feature. It accepts an object with key properties that define the slice's behavior — including its name, initial state, and reducers.
name: A string that identifies the slice and prefixes generated action types.
initialState: Defines the default state for that slice of the store.
reducers: An object containing reducer functions that define how the state changes in response to actions. Action creators are automatically generated from these.
extraReducers (optional): Handles actions defined outside the slice, such as those created by createAsyncThunk or other slices.
We need a simple counter slice with an increment action and a loading flag. Which properties would you include in createSlice and how would you set them up?
If you forget to provide a 'name' when calling createSlice, what error or behavior do you see at runtime?
What happens if you place a non‑serializable object (like a Date) in the initialState of a slice?
You have a thunk that fetches user data and you want the user slice to react to its pending/fulfilled/rejected actions. How would you configure createSlice to handle those external actions?
During debugging you notice that an action defined in the slice's reducers isn’t updating the state. What could be wrong with how the reducers were declared inside createSlice?
Explain the trade‑offs between putting async‑related case handling in reducers versus extraReducers.
Your app now has dozens of slices and the bundle size is growing. How would you organize your createSlice definitions to reduce duplication and keep the codebase maintainable?
When integrating RTK Query with existing slices, you need to share loading/error state. How would you design the slice’s extraReducers to efficiently handle the pending/fulfilled/rejected actions from the query?
Describe how you’d use the prepare callback in createSlice to enforce type‑safe payloads across many slices.
We’re migrating a large legacy Redux codebase to Redux Toolkit. What systematic approach would you take to refactor existing reducers into createSlice calls, and how would you handle naming collisions and shared logic?
In a micro‑frontend setup, multiple teams own slices that are loaded dynamically at runtime. How would you design the slice creation (name, extraReducers, etc.) to avoid action‑type conflicts and support hot‑loading?
Consider a scenario where several independent teams need to extend a core slice with additional case reducers without modifying the original file. How would you structure createSlice and extraReducers to enable this extensibility?