What is Redux Toolkit?
Redux Toolkit (RTK) is the official, recommended way to write Redux logic. It simplifies store setup, reduces boilerplate, and includes best practices by default.
🚀 Setup
// Install
npm install @reduxjs/toolkit react-redux
// store.js
import { configureStore } from '@reduxjs/toolkit';
import counterReducer from './counterSlice';
const store = configureStore({
reducer: {
counter: counterReducer
}
});
export default store;🎯 Key Takeaways
- createSlice: Creates reducer + actions
- configureStore: Simplified store setup
- Immer: Write mutable code that becomes immutable
- createAsyncThunk: Handle async actions
- RTK Query: Data fetching and caching