DEV Community

Cover image for Redux Toolkit-A standard way to write redux
MD Zahid Hasan
MD Zahid Hasan

Posted on

Redux Toolkit-A standard way to write redux

What is Redux Toolkit?
Redux Toolkit is the new reliable way to consist of Redux into your project. It attempts to resolve a number of the common issues developers expressed in using the original Redux package. along with an excessive amount of setup, too complex, and desiring too many addon applications to function. With the toolkit, there may be much less configuration and a lot more work is performed under the hood and middlewares had been included with async thunks. while the original Redux package become very unopinionated and allowed you to choose which packages you desired to use with it, the new Redux Toolkit is opinionated as it comes with those packages out of the sector. you can consider Redux Toolkit as the Create React App for Redux as it comes with matters that will help get you started faster.

API includes Redux Toolkit

configureStore(): wraps createStore to provide simplified configuration options and good defaults. it could automatically integrate your slice reducers, provides something Redux middleware you supply, consists of redux-thunk by default, and enables the use of the Redux DevTools Extension.

createReducer(): Reducer support directly mapping specific action types to case reducer function that will update the state when that action is dispatched.

createAction(): Based on given action type string it generates a action creator function.This function has its own toString() method so that it can be used as a type constant.

createSlice(): createSlice is a higher-order function that accepts an initial state, an object full reducer function, and a slice name. it automatically generates action creators and action types that correspond to the reducers and state.

createAsyncThunk: Accepts an action type string and a function that returns a promise, and generates a thunk that dispatches pending/fulfilled/rejected action types based on that promise.

createEntityAdapter: Generates a set of reusable reducers and selectors to manage normalized data in the store.

createSelector(): Selectors typically expect the Redux state object as an argument, while slice reducers only have access to a specific subset of the entire Redux state.

Top comments (0)