Redux and React-Native

The concept of Redux is similar to the concept of  sessions in .Net world. Redux is a framework used to effectively manage the temporary information called State which can be used through the application. Examples of such temporary information could be data retrieved from database that needs to stored temporarily in a global object, in this case State, that can be accessed throughout the application.

Redux is a framework on its own and has nothing to do with react-native. In order for react-native to use Redux framework, react redux package needs to be installed inside the react native project using the below command line.

npm install –save redux react-redux

react-redux framework uses provider to connect react components with Redux. Provider establishes the communication between React-Native framework and Redux by using connect() which connects the components to the State of the application.

Redux manages the state using three important features: Stores, actions and reducers. Actions as the name implies is the functionality that needs to be executed like for e.g., saving a to-do list in the state. Actions are fed to the reducer which changes the state like for e.g., the logic to save the to-do list lies in the reducer. However, both actions and reducers are useless by themselves without Store. Store is the object that coordinates the communication between action and reducers by dispatching action to the reducer.

When the application starts all the reducers are ran and the corresponding objects inside the reducer are populated to produce the state. Since the state objects are pre-populated, any component can access the State using the function connect() in the Provider framework. These states can be later modified as necessary by dispatching an action. Note that there can be multiple reducers for an application to hold different forms of data like for e.g., to hold the name of persons and another to hold the details of each person etc..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s