5 Mins Read
Why we prefer Redux Toolkit over Traditional Redux?
“Sometimes, you have to let go of a good thing to get a better one.”
State Management is one of the most important parts of any app. It helps improve the app’s performance greatly. One of the most widely used solutions for React Native is Redux. Although it is a very popular technique still has some limitations.
The Problem Statement
Redux is great but does have a few limitations:
1. Configuring a Redux store is too complicated and requires a lot of initial setups.
2. You need to add a lot of packages to get Redux to do even basic stuff.
3. Redux requires too much boilerplate code.
Keeping these limitations in mind, our Kristal Mobile Team took a deep dive into the vast internet to look for a better solution. On our adventurous journey spanning a number of possible solutions, we finally stumbled upon a solution that worked — Redux Toolkit.
Here are some of the benefits of Redux Toolkit over Redux :
- It saves us from a ton of boiler-plate code as it comes with pre-configured methods and APIs.
- It helps in faster development since less code needs to be written.
- It provides all the functionalities of Redux minus the above limitations.
Below are the steps for adding Redux Toolkit to the project :
- For adding redux toolkit to the project we simply need to add two libraries @reduxjs/toolkit and react-redux.
- The library includes all the necessary APIs for state management like :
– configureStore: provides options for redux store configuration and includes redux-thunk middleware by default.
– createSlice: simple API which gives the ability to create a Redux Store and provides options for adding initial state, reducers, extra reducers, and name.
- It also provides actions and reducers as it internally uses create action and create reduced API provided by redux toolkit.
– Reducers: they are used for actions created for that particular slice.
– Extra reducers: they are used for actions that are defined somewhere else for example Async Actions.
– createAsyncThunk: and pi which is used for processing asynchronous tasks and generating actions.
– It returns an object containing name, reducers, and actions, the actions can be used for dispatching which can be defined at any event or actions by the user.
While Redux is good, Redux Toolkit provides many functionalities out-of-the-box and avoids most of the boring boilerplate code. It makes the code lean, clean, and simple to manage, and that’s why the Kristal team prefers Redux Toolkit.
This blog article has not been reviewed by the MAS. It is prepared solely for information purposes and does not constitute an offer or solicitation for the purchase or sale of units in the funds. This does not constitute any form of investment advice and Kristal Advisors (SG) Pte Ltd does not take into account your personal investment objectives, specific investment goals, specific needs, or financial situation and makes no representation and assumes no liability to the accuracy or completeness of the information provided here. The information and publications are not intended to be and do not constitute financial advice, investment advice, trading advice or any other advice or recommendation of any sort offered or endorsed by Kristal Advisors (SG) Pte Ltd.
Other stories you might like
5 Mins Read
5 Mins Read