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

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 l

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 elements is low. Now let’s discuss each principle one by one. 1.)  Single Responsibility Principl

What's new in iOS 13

Hi guys, Lets have a quick review on what new features Apple has released in its latest iOS 13 version. iOS 13 version iOS 13 makes old iPhone faster, last longer  - In iOS 13, Face ID unlocking will be 30% faster than before , app launch times are two times faster. Apple also found a way to make app downloads smaller, up to 60% on average. iOS 13 Dark Mode  - Apple introduced new dark mode option which changes the entire look of the operating system from light to dark. All native Apple apps feature Dark Mode support, and third-party apps can use Dark Mode APIs to add Dark Mode integration. iOS 13 features a QuickPath keyboard  - With iOS 13, Apple's default QuickType keyboard will be incorporating swipe-to-type, a popular way of sliding across the keyboard to form words. Before this, we have to use extensions like Google’s Gboard and SwiftKey Sign - In with Apple - Now, we can use Apple sign In to  conveniently sign in to third-party accounts.Sign-in with A