Redux is state management library in react native application which is used to manage the entire application state. It helps us to create applications that behave consistently, can run in different environments and are easy to test.
Why we need it
In react native, we have components where we can manage states internally. It does well when the application have fewer components but when the size of application grows the task of sharing the states between the components become quite difficult.
But this management of different states in our application becomes easy in redux because in redux we have a single centralised global store which contain all the states of the application which is accessible to any component which subscribe to the store. So the task of passing states via props between the components gets eliminated.
Redux is made up of store, actions, reducer and dispatcher. Let’s discuss about them.
Store
Store is basically a place where we manage all the states of our application and each state has its own data.
Actions
Action are javascript objects which are used to modify state in the store. They are basically a payload of information that sends the data from our application to the store. So whenever we have to change the state of any component then me must dispatch an action.
Reducers
Reducer are the functions which receive the actions, modify the states based on the action and return the new state. It is important to note here that we never mutate the state inside the reducer, we always return a new copy of state.
Dispatcher
It is the one which sends the actions to the reducer. For example when we clicked any button, then its onPress function could be a dispatcher which sends particular action to the reducer.
Benefits of Redux
· Since there is only one store in redux which contains all the states of the application, so any component any access any state from the store. Therefore no need to pass props back and forth.
· The state of component persists even when the component has unmounted.
· Testing part becomes easy because UI building and data management get separated.
If you enjoyed reading this article 🙂, then please don’t forget to share it with your friends and do subscribe this blog to receive more technical posts in future via email.
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site. For more info:- React native App Development
ReplyDelete