Q1. What is Redux Toolkit?
Redux Toolkit is the official, opinionated toolset for efficient Redux development.
It simplifies common Redux tasks, reduces boilerplate, and includes utilities like
It simplifies common Redux tasks, reduces boilerplate, and includes utilities like
createSlice, configureStore, and createAsyncThunk.Q2. What is createSlice?
It uses Immer internally to allow mutable-like syntax.
Example:
createSlice automatically generates action creators and action types based on the reducers you define.It uses Immer internally to allow mutable-like syntax.
Example:
const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment: (state) => { state.value += 1; }
}
});
Q3. How do you configure a store with Redux Toolkit?
Use
Example:
configureStore which automatically sets up the store with good defaults, including thunk middleware and DevTools.Example:
const store = configureStore({ reducer: { counter: counterSlice.reducer } });Q4. What is createAsyncThunk?
It generates action types for pending, fulfilled, and rejected states.
You provide a payload creator that returns a promise, and reducers can handle those actions.
createAsyncThunk simplifies handling asynchronous actions.It generates action types for pending, fulfilled, and rejected states.
You provide a payload creator that returns a promise, and reducers can handle those actions.
Q5. Why use Redux Toolkit over plain Redux?
It reduces boilerplate, enforces best practices, and includes powerful tools like Immer and Redux DevTools integration.
It's the recommended way to write Redux logic.
It's the recommended way to write Redux logic.
