Skip to main content

What is Redux in React Native and why we need it ?

what is redux
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.

Comments

  1. 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

Post a Comment

Popular posts from this blog

How to communicate between React Native and Swift using Bridging

In this article we will learn how can we achieve communication between React Native and Swift code. As we know React Native (RN) is great for building cross platform apps, but during development of react native app we might come across a situation where we need to call native code written in swift. This is where bridge module comes in, which allows us to communicate with the native layer of the application. If we are developing app in React Native for iOS and Android platform then we need to create a bridge for each platform. In this article we will discuss creation of React Native Bridge for iOS only. So Let’s start To better understand the concept we will create sample DemoApp in react native using react native CLI. Below are the commands to setup new project in react native. ·       react-native init DemoApp ·       cd DemoApp ·       react-native run-ios On running the app on iOS s...

SOLID Design Principles in Swift

What are solid principles in programming world? 5 SOLID design principles in swift SOLID is acronym used in software programming for making software design more understandable, flexible, scalable and maintainable.  Every Software Developer must be aware of 5 SOLID principles in order to deliver good quality code SOLID stands for what? S -  Single Responsibility principle O - Open Closed Principle L - Liskov substitution Principle I - Interface segregation Principle D - Dependency Inversion Principle If we apply 5 SOLID principles while creating iOS/Mac Apps then the benefits which we will get are as follow: ·       We will have flexible code which can be changed easily. ·       Software code becomes more reusable. ·       Software developed will be robust, scalable and stable. ·       Code is loosely couple which means dependency between the...

Lifecycle of React Native Component [2020 Edition]

What are the life cycle methods of React Native Component? A component's life cycle in React Native can be divided into 4 phases: React Native Component life cycle phases Mounting:  In this phase,  component instance is created and inserted into the DOM. Updating: In updating phase, a react component is said to be born and it start growing by receiving new updates. Unmounting: In this phase, a react component gets removed from actual DOM. Error Handling: It is called when any error occurs while rendering the component. Now let's discuss about different methods that gets called during these phases. Mounting phase Below are the methods which gets called when instance of component is created and inserted into the DOM. Constructor() static getDerivedStateFromProps() render() ComponentDidMount() Constructor() constructor ( props ) { super ( props ) ; this . state = { employeeId : 0 } ; } It is first method which gets called in the ...