Redux Toolkit
![[Pasted image 20250924113607.png]]
Redux Toolkit includes these APIs:
configureStore(): wrapscreateStoreto provide simplified configuration options and good defaults. It can automatically combine your slice reducers, adds whatever Redux middleware you supply, includesredux-thunkby default, and enables use of the Redux DevTools Extension.createReducer(): that lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses theimmerlibrary to let you write simpler immutable updates with normal mutative code, likestate.todos[3].completed = true.createAction(): generates an action creator function for the given action type string.createSlice(): accepts an object of reducer functions, a slice name, and an initial state value, and automatically generates a slice reducer with corresponding action creators and action types.combineSlices(): combines multiple slices into a single reducer, and allows "lazy loading" of slices after initialisation.createAsyncThunk: accepts an action type string and a function that returns a promise, and generates a thunk that dispatchespending/fulfilled/rejectedaction types based on that promisecreateEntityAdapter: generates a set of reusable reducers and selectors to manage normalized data in the store- The
createSelectorutility from the Reselect library, re-exported for ease of use.
slice - feature from a global state
createSlice(
name: 'nameOfTheStore',
initialState: [],
reducerLogic: {
action.type: (state, action) => {
return updatedState
}
}
)Immer is a library to update states immutably instead of using spread operator