SlideShare a Scribd company logo
1 of 7
Download to read offline
International Journal of Trend in Scientific Research and Development (IJTSRD)
Volume 6 Issue 7, November-December 2022 Available Online: www.ijtsrd.com e-ISSN: 2456 – 6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1021
Redux State Management System - A Comprehensive Review
Krutika Patil
Master of Science in Computer Science, The University of Texas at Dallas, Tracy, CA, USA
ABSTRACT
Reactivity is a common trait of JavaScript applications and comes
with efficient state management. Any JavaScript application has
multiple ways of managing state; for example, in React, we can use
"useState” and “useReducer" Hooks. However, another third-party
library called Redux has grown in popularity to be an efficient state
management tool in JavaScript applications. This paper makes an in-
depth review of the Redux state management system. It is famously
used with React as a state-management tool and by other JavaScript
frameworks as well. Redux is most suitable for applications with
frequent updates to the state since Redux has better efficiency in a
flux-like setup than React's Context API.
KEYWORDS: ReactJs, Redux, state management, web development,
JavaScript frameworks, React context, cross-component state, app-
wide state, local state
How to cite this paper: Krutika Patil
"Redux State Management System - A
Comprehensive Review" Published in
International Journal
of Trend in
Scientific Research
and Development
(ijtsrd), ISSN: 2456-
6470, Volume-6 |
Issue-7, December
2022, pp.1021-
1027, URL:
www.ijtsrd.com/papers/ijtsrd52530.pdf
Copyright © 2022 by author (s) and
International Journal of Trend in
Scientific Research
and Development
Journal. This is an
Open Access article distributed under
the terms of the Creative Commons
Attribution License (CC BY 4.0)
(http://creativecommons.org/licenses/by/4.0)
INTRODUCTION
Redux is a third-party JavaScript library. It has
quickly gained recognition in the front-end world as
the most efficient state-management system in an
application with frequent state updates. It is a state-
management system for cross-component and app-
wide states. To understand the concept of various
states, let us classify the different types of states.
There are three states in a JavaScript application.
Figure 1: Classification of States in a
JavaScript application
Local state - a state limited to a single
component. For example, listening to a click event
for a button or a user input for a text field. Usually
handled in React applications bythe “useState” or
the “useReducer” hook.
Cross-component state - a state that affects
multiple components. For example, opening and
closing a modal overlay. In the case of a cross-
component state, multiple components share the
state. We achieve this state management using
prop chains and prop drilling.
App-wide state - affects the entire application or,
at least, most components. One example of this
could be the authentication status. Whether
authenticated or not, the components might choose
to hide, show, or update the content they render.
We can use prop drilling and prop chains to
achieve this state management.
In the case of Cross-component and App-wide
states, the "prop-drilling" and "prop-chaining" can
get cumbersome since the props get passed around
component hierarchies which might increase the
chances of introducing defects in the logic. We can
instead use the Redux library to manage the state
for us in these cases. Redux maintains a central data
store that the components can subscribe to and then
IJTSRD52530
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1022
dispatch specific actions if the state needs to be
updated.
These concepts are depicted diagrammatically in
Figure 1.
CORE CONCEPTS OF REDUX
A. Central Data Store
Figure 2: Core Concepts of Redux
Redux has a single central data store.
Components can subscribe to a store to get any
updates to the state or a part of the state. The
components would also need a way to change the
state. One important thing is that components never
directly change or mutate a store. Instead, we use the
Reducer function.
B. Reducers
A reducer is a programming concept. It is a function
that is responsible for mutating or updating the store.
A reducer is a pure function, meaning it should always
produce the same output for the same input. We
should not add side-effect logic (API calls or reading
and writing to local storage) in the reducer functions.
The components must use the reducers if they need to
change or update the store. A reducer function always
needs to be triggered by a component—for example,
clicking a button or a user input on a text field. Hence,
we need a way for components to do that. The concept
of actions comes into play here.
C. Actions
The components dispatch or trigger actions, and the
actions are JavaScript objects which include the
description of the action and optionally contain a
payload. The components dispatch these actions
that contain a description of the intended action.
The redux then forwards these actions to the
reducer. The reducer reads the action description
that describes the action and updates or mutates the
state accordingly. We need to note here that
components DO NOT directly update the store.
Instead, the components dispatch actions, which get
forwarded to the reducers. The reducer then spits a
new state that replaces the existing state in the
central data store. When the central state updates,
the components that have subscribed to the store
receive notifications instantly so that the
components can update their UI. Figure 2 above
describes in detail the concepts we discussed in this
section.
BASIC REDUX EXAMPLE IN JAVASCRIPT
A. Setting up the central data store
Consider the below script in Figure 3.
Figure 3 Basic redux script in JavaScript
Let us see the core concepts of Redux discussed in
the previous section in action using the example
above in Figure 3. First off, we import redux using
the statement below in Figure 4.
Figure 4 System to import redux in a
JavaScript application
The require("redux") expression returns a redux
const that will be our Hook to the central data store.
Next, let us create the central store on which the
redux state management functionality depends. We
can create a store using the statement below in
Figure 5.
Figure 5: Syntax to create a central data store
in a JavaScript application
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1023
The function legacy_createStore returns a store
object. The components subscribe to this store. It also
takes in an argument which is our reducer. The
reducer function mutates the store by spitting out a
new state snapshot that replaces the previous one.
Hence, this becomes the input to the
legacy_createStore function.
Next, let us look at the way to create a reducer.
Consider the code below in Figure 6. A reducer is a
JavaScript function. It takes in two arguments: state
and action. The state is the current state snapshot and
is forwarded to the reducer by redux. The second
argument, "action”, is passed to the reducer by the
components. This argument action contains a property
type that describes the type of action. Based on the
type of action, a particular state snapshot gets returned
by the reducer. This state snapshot replaces the
existing state in the central store.
Figure 6 A typical redux reducer function
Components can subscribe to the store using the
function below in Figure 7.
Figure 7 Subscriber function to a Redux store
In the example above in Figure 7, the subscriber is a
function that executes the logic to get the updates
from the store using the store.getState(). As the state
in the central store changes, the components
subscribed to the store get notified instantly to update
the UI.
The components can update the state by dispatching
specific actions using the logic in Figure 8.
Figure 8 Logic to dispatch a Redux action
We dispatch the action to increment the flag state in
the above code. The dispatch function takes in an
argument that is a JavaScript object and contains the
type property. This property describes the type of
action. We may also send a payload if we update the
state to a specific value.
Figure 9 A Redux Reducer function in
JavaScript
The dispatched action is forwarded to the reducer
function by redux. An example of that is depicted
above in Figure 9.
We dispatch three actions in our script.
store.dispatch({type: 'increment'});
store.dispatch({type: 'increment'});
store.dispatch({type: 'increment', payload: 50});
Hence, our output would be as depicted in Figure 10.
The first output is for the action increment that
increases the flag value to 1 from its initial value of 0.
The second output is for the dispatched action
decrement that decrements the flag value to 0 from 1.
Furthermore, the third value is due to the action
"incrementBy", which also contained a payload of 50.
The action increments the flag by 50 from 0.
Figure 10 Output of the script depicted in Figure
3
USING REDUX IN A REACT APPLICATION
Consider a simple react project below in Figure 11. It
prints out the value of the flag that is initially 0. There
are four buttons to perform various operations that we
will cover soon.
Figure 11 A simple React App
Let us now install redux into the application. To do
that, we need to get the reduxjs/toolkit, a third-party
package that makes working with redux very easy.
The command to install redux is depicted below in
Figure 12.
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1024
Figure 12 Command to install reduxjs/toolkit
library in a React Application.
Next, we will install react-redux, another package
that gives us access to libraries responsible for
dispatching actions and subscribing to a store. The
syntax is depicted below in Figure 13.
Figure 13 Command to install react-redux in a
React Application.
Once done, let us go ahead and create our central store
that stores the state. A vital feature given by the redux
toolkit is that we can have slices of the state. We can
split the state into two slices for our current React
application in Figure 11. A UI Slice manages the state
to display or hide the flag; a Flag Slice could maintain
the flag state.
Let us start by creating the UI Slice. We must import
the createSlice library from the redux toolkit to create
our slice script. Figure 14 depicts the syntax.
Figure 14 Syntax to import createSlice hook
function from reduxjs/toolkit
The createSlice is a function. It takes in an object
with the following three properties: a name property
that uniquely identifies the state slice, an initialState
property with which the state gets initialized, and the
reducers property where we can list the various
actions supported by this slice.
The logic to create a state slice looks as below in
Figure 15.
Figure 15 Logic to create a state slice to toggle
the flag visibility
Here, the reducers property is, in turn, an object with
various actions that are supported. We see that
toggleFlag modifies the state by flipping the previous
value. We notice here that the initial state is true.
Similarly, let us also create the flagSlice. We will
have three actions in the flagSlice as supported by the
reducer. The export flagSlice.reducer gives us access
to this reducer. The components use the export
"flagActions" to dispatch various actions.
Our next step is to configure these reducers in our
store. Let us create a new script file and import
configureStore from reduxjs/toolkit. The syntax is
depicted below in Figure 16.
Figure 16 Syntax to import configureStore from
reduxjs/toolkit
This function configureStore takes in an argument
which is a JavaScript object. This JavaScript object
needs to list out the reducers. We can achieve this by
adding an object with property reducers, and its value
could be another object with any key that the user
prefers and its value being a reducer. Below in Figure
17, we have configured both the reducers into the
store.
Figure 17 Configuring a Redux store in React by
combining multiple state slices.
The store needs to be made available to the entire
application. We can do this in the index.js file in the
root folder. Import the store from the store folder. We
also need to import Provider from the react-redux
library. The Provider is a React element, and by
wrapping it around our main App component, we will
make the store available to the app. The Provider
element takes in a prop, the store object imported from
the redux script. The code looks like the one below in
Figure 18.
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1025
Figure 18 Making the Redux store available to
the entire application
Following the above steps, we successfully set up our
React application with Redux. The following section
discusses how to dispatch an action on the store and
subscribe to the store.
B. Dispatching Actions to the central data store
The components need to import the “useDispatch”
Hook from react-redux. This Hook, when executed,
gives us a dispatch constant that we can use to trigger
our actions. The logic to import useDispatch Hook is
as below in Figure 19.
Figure 19 Syntax to import the useDispatch
Hook from react-redux library
Execute the useDispatch Hook inside the component
to retrieve a dispatch constant, as depicted in Figure
20.
Figure 20 Executing useDispatch Hook to
retrieve a dispatch constant.
Next, we would like to dispatch specific actions when
clicking the buttons. For example, the Toggle Flag
button will show or hide the flag. The Increment
button will increment the flag. The Decrement button
will decrement the flag. Furthermore, we need to
increment the flag by a certain number upon clicking
the "Increment By 10" button. For this, let us import
the actions from our reducer scripts. The syntax is
depicted below in Figure 21.
Figure 21 Importing the Reducer actions from
the Reducer scripts
Let us consider clicking on the button Toggle Flag.
We want to show or hide the flag when clicking this
button. We essentially dispatch the action
“toggleFlag" in this case which gets forwarded to the
Reducer by Redux. The syntax is depicted below in
Figure 22.
Figure 22 Dispatching a Redux Action from a
component
The function toggleFlagHandler dispatches the
toggleFlag action, and as we know, the toggleFlag
action in the uiActions reducer flips the showFlag
state.
Similarly, consider incrementing the flag by clicking
on the Increment button. The button's onClick
handler executes the incrementHandler function that
dispatches the incrementFlag action. We have
depicted the same in Figure 23.
Figure 23 Dispatching increment Flag,
decrement Flag and increment By actions
C. Subscribing to the store
The components need to import the "useSelector”
Hook from the react-redux library to get updates from
the store. The import syntax is depicted below in
Figure 24. When the central state in the store updates,
the subscribing components get updated instantly.
Figure 24 Syntax to import “useSelector” Hook
from ‘react-redux’ library
We need to execute the "useSelector" Hook inside the
components only. It takes in an argument that is a
state and returns the specific state that we need. The
logic looks like below. When we set up our store, we
added keys to the specific reducers ui and flag. Hence,
while retrieving the state, we need to use these keys to
refer to a state of our choice. We have depicted the
same in Figure 25.
Figure 25 Syntax to retrieve the state from the
store
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1026
The retrieved state showFlag updates whenever the
state.ui.showFlag changes, thereby re-rendering the
component. The exact mechanism applies to the other
buttons that trigger their actions, resulting in reducers
performing appropriate state updates based on the
action types.
RESULTS
The initial state of the UI is depicted below in Figure
26.
Figure 26 Initial state of the UI
Below are the results on the UI due to clicking on
Increment, Decrement, Increment By 10, and
Toggle Flag buttons, respectively. These are depicted
respectively in Figure 27 - 30.
The first action triggered due to a click event on the
"Increment” button is the “incrementFlag" action.
The initial state 0 of the "flag" got updated to 1.
The second action triggered due to a click event on the
"Decrement” button is the “decrementFlag" action.
The initial state 1 of the "flag" got updated to 0.
The third action triggered due to a click event on the
"Increment By 10” button is the “incrementBy”
action. The initial state 0 of the "flag" got updated to
50.
The fourth action triggered due to a click event on the
"ToggleFlag” button is the “toggleFlag” action. With
the initial state of the “showFlag” state in the store
being “true", it was updated to “false”.
Since the components have subscribed to the store, the
updates are reflected on the UI instantaneously.
Figure 27 UI State after clicking on the
“Increment” button
Figure 28 UI State after clicking on the
“Decrement” button
Figure 29 UI State after clicking on the
“Increment By 10” button
Figure 30 UI State after clicking on the “Toggle
Flag” button
CONCLUSION
This paper attempts to dive deep into the features of
the Redux state management mechanism. We started
with understanding managing the state in an
application and looked at various aspects of Redux,
like the central data store, actions, and reducers.
Also, we discussed the subscription mechanism of
the components to the store to get instant updates. We
looked at how we can split the state into multiple
slices that serve a specific purpose. The reducers can
update the slices only, and behind the scenes, the
Redux will combine the state snapshot into the overall
state. The feature of Redux discussed in this paper
helps us de-clutter the logic into respective scripts and
helps make the code easy to maintain. The Redux
statement system can be a good option in a flux-like
system with frequent updates to the state.
REFERENCES
[1] Krutika Patil, Sanath DhananjayamurtyJavagal,
"React state management and side-effects – A
Review of Hooks", IRJET Journal, volume 9,
2022,
https://www.irjet.net/archives/V9/i12/IRJET-
V9I1225.pdf.
[2] https://www.udemy.com/course/react-the-
complete-guide-incl-
redux/learn/lecture/25599228?start=405#overvi
ew
[3] Shravan G V, Anitha Sandeep.
"COMPREHENSIVEANALYSISOFREACT-
REDUX DEVELOPMENT FRAMEWORK",
International Journal of Creative Research
Thoughts (IJCRT), ISSN:2320-2882, Vol.8,
Issue 4, pp.4230-4233, April 2020, URL:
http://www.ijcrt.org/IJCRT2004607
[4] Banks, Alex, and Eve Porcello. Learning React:
functional web development with React and
Redux. " O'Reilly Media, Inc.", 2017.
[5] Caspers, Matthias Kevin. "React and redux."
Rich Internet Applications w/HTML and
Javascript 11 (2017).
International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470
@ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1027
[6] Chinnathambi, Kirupa. Learning React: A
Hands-on Guide to Building Web Applications
Using React and Redux. Addison-Wesley
Professional, 2018.
[7] McFarlane, Timo. "Managing State in React
Applications with Redux." (2019).
[8] Roldan, Carlos Santana. React Cookbook:
Create dynamic web apps with React using
Redux, Webpack, Node. js, and GraphQL.
Packt Publishing Ltd, 2018.
[9] Bugl, Daniel. Learning Redux. Packt Publishing
Ltd, 2017.
[10] Pronina, Daria, and Iryna Kyrychenko.
"Comparison of Redux and React Hooks
Methods in Terms of Performance."
Proceedings http://ceur-ws. org ISSN 1613
(2022): 0073

More Related Content

Similar to Redux State Management System A Comprehensive Review

Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Interview Questions On React JS.pptx
Interview Questions On React JS.pptxInterview Questions On React JS.pptx
Interview Questions On React JS.pptxDucatNoida1
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of ReduxInnovationM
 
Everything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideEverything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideBOSC Tech Labs
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxBOSC Tech Labs
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksKaty Slemon
 
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdfArthyR3
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and reduxCuong Ho
 
Unidirectional Data Flow Architecture (Redux) in Swift
Unidirectional Data Flow Architecture (Redux) in SwiftUnidirectional Data Flow Architecture (Redux) in Swift
Unidirectional Data Flow Architecture (Redux) in SwiftSeyhun AKYUREK
 
How to use redux with react hooks in react native application
How to use redux with react hooks in react native applicationHow to use redux with react hooks in react native application
How to use redux with react hooks in react native applicationKaty Slemon
 

Similar to Redux State Management System A Comprehensive Review (20)

Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React
ReactReact
React
 
Interview Questions On React JS.pptx
Interview Questions On React JS.pptxInterview Questions On React JS.pptx
Interview Questions On React JS.pptx
 
ReactJs
ReactJsReactJs
ReactJs
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
Everything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive GuideEverything to Know About React Re-Rendering: A Comprehensive Guide
Everything to Know About React Re-Rendering: A Comprehensive Guide
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
 
Copy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdfCopy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdf
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooks
 
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
 
Redux
ReduxRedux
Redux
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
reactJS
reactJSreactJS
reactJS
 
Redux essentials
Redux essentialsRedux essentials
Redux essentials
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
Redux Like Us
Redux Like UsRedux Like Us
Redux Like Us
 
Unidirectional Data Flow Architecture (Redux) in Swift
Unidirectional Data Flow Architecture (Redux) in SwiftUnidirectional Data Flow Architecture (Redux) in Swift
Unidirectional Data Flow Architecture (Redux) in Swift
 
How to use redux with react hooks in react native application
How to use redux with react hooks in react native applicationHow to use redux with react hooks in react native application
How to use redux with react hooks in react native application
 

More from ijtsrd

‘Six Sigma Technique’ A Journey Through its Implementation
‘Six Sigma Technique’ A Journey Through its Implementation‘Six Sigma Technique’ A Journey Through its Implementation
‘Six Sigma Technique’ A Journey Through its Implementationijtsrd
 
Edge Computing in Space Enhancing Data Processing and Communication for Space...
Edge Computing in Space Enhancing Data Processing and Communication for Space...Edge Computing in Space Enhancing Data Processing and Communication for Space...
Edge Computing in Space Enhancing Data Processing and Communication for Space...ijtsrd
 
Dynamics of Communal Politics in 21st Century India Challenges and Prospects
Dynamics of Communal Politics in 21st Century India Challenges and ProspectsDynamics of Communal Politics in 21st Century India Challenges and Prospects
Dynamics of Communal Politics in 21st Century India Challenges and Prospectsijtsrd
 
Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...
Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...
Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...ijtsrd
 
The Impact of Digital Media on the Decentralization of Power and the Erosion ...
The Impact of Digital Media on the Decentralization of Power and the Erosion ...The Impact of Digital Media on the Decentralization of Power and the Erosion ...
The Impact of Digital Media on the Decentralization of Power and the Erosion ...ijtsrd
 
Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...
Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...
Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...ijtsrd
 
Problems and Challenges of Agro Entreprenurship A Study
Problems and Challenges of Agro Entreprenurship A StudyProblems and Challenges of Agro Entreprenurship A Study
Problems and Challenges of Agro Entreprenurship A Studyijtsrd
 
Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...
Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...
Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...ijtsrd
 
The Impact of Educational Background and Professional Training on Human Right...
The Impact of Educational Background and Professional Training on Human Right...The Impact of Educational Background and Professional Training on Human Right...
The Impact of Educational Background and Professional Training on Human Right...ijtsrd
 
A Study on the Effective Teaching Learning Process in English Curriculum at t...
A Study on the Effective Teaching Learning Process in English Curriculum at t...A Study on the Effective Teaching Learning Process in English Curriculum at t...
A Study on the Effective Teaching Learning Process in English Curriculum at t...ijtsrd
 
The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...
The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...
The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...ijtsrd
 
Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...
Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...
Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...ijtsrd
 
Sustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. Sadiku
Sustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. SadikuSustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. Sadiku
Sustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. Sadikuijtsrd
 
Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...
Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...
Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...ijtsrd
 
Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...
Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...
Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...ijtsrd
 
Activating Geospatial Information for Sudans Sustainable Investment Map
Activating Geospatial Information for Sudans Sustainable Investment MapActivating Geospatial Information for Sudans Sustainable Investment Map
Activating Geospatial Information for Sudans Sustainable Investment Mapijtsrd
 
Educational Unity Embracing Diversity for a Stronger Society
Educational Unity Embracing Diversity for a Stronger SocietyEducational Unity Embracing Diversity for a Stronger Society
Educational Unity Embracing Diversity for a Stronger Societyijtsrd
 
Integration of Indian Indigenous Knowledge System in Management Prospects and...
Integration of Indian Indigenous Knowledge System in Management Prospects and...Integration of Indian Indigenous Knowledge System in Management Prospects and...
Integration of Indian Indigenous Knowledge System in Management Prospects and...ijtsrd
 
DeepMask Transforming Face Mask Identification for Better Pandemic Control in...
DeepMask Transforming Face Mask Identification for Better Pandemic Control in...DeepMask Transforming Face Mask Identification for Better Pandemic Control in...
DeepMask Transforming Face Mask Identification for Better Pandemic Control in...ijtsrd
 
Streamlining Data Collection eCRF Design and Machine Learning
Streamlining Data Collection eCRF Design and Machine LearningStreamlining Data Collection eCRF Design and Machine Learning
Streamlining Data Collection eCRF Design and Machine Learningijtsrd
 

More from ijtsrd (20)

‘Six Sigma Technique’ A Journey Through its Implementation
‘Six Sigma Technique’ A Journey Through its Implementation‘Six Sigma Technique’ A Journey Through its Implementation
‘Six Sigma Technique’ A Journey Through its Implementation
 
Edge Computing in Space Enhancing Data Processing and Communication for Space...
Edge Computing in Space Enhancing Data Processing and Communication for Space...Edge Computing in Space Enhancing Data Processing and Communication for Space...
Edge Computing in Space Enhancing Data Processing and Communication for Space...
 
Dynamics of Communal Politics in 21st Century India Challenges and Prospects
Dynamics of Communal Politics in 21st Century India Challenges and ProspectsDynamics of Communal Politics in 21st Century India Challenges and Prospects
Dynamics of Communal Politics in 21st Century India Challenges and Prospects
 
Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...
Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...
Assess Perspective and Knowledge of Healthcare Providers Towards Elehealth in...
 
The Impact of Digital Media on the Decentralization of Power and the Erosion ...
The Impact of Digital Media on the Decentralization of Power and the Erosion ...The Impact of Digital Media on the Decentralization of Power and the Erosion ...
The Impact of Digital Media on the Decentralization of Power and the Erosion ...
 
Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...
Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...
Online Voices, Offline Impact Ambedkars Ideals and Socio Political Inclusion ...
 
Problems and Challenges of Agro Entreprenurship A Study
Problems and Challenges of Agro Entreprenurship A StudyProblems and Challenges of Agro Entreprenurship A Study
Problems and Challenges of Agro Entreprenurship A Study
 
Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...
Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...
Comparative Analysis of Total Corporate Disclosure of Selected IT Companies o...
 
The Impact of Educational Background and Professional Training on Human Right...
The Impact of Educational Background and Professional Training on Human Right...The Impact of Educational Background and Professional Training on Human Right...
The Impact of Educational Background and Professional Training on Human Right...
 
A Study on the Effective Teaching Learning Process in English Curriculum at t...
A Study on the Effective Teaching Learning Process in English Curriculum at t...A Study on the Effective Teaching Learning Process in English Curriculum at t...
A Study on the Effective Teaching Learning Process in English Curriculum at t...
 
The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...
The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...
The Role of Mentoring and Its Influence on the Effectiveness of the Teaching ...
 
Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...
Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...
Design Simulation and Hardware Construction of an Arduino Microcontroller Bas...
 
Sustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. Sadiku
Sustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. SadikuSustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. Sadiku
Sustainable Energy by Paul A. Adekunte | Matthew N. O. Sadiku | Janet O. Sadiku
 
Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...
Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...
Concepts for Sudan Survey Act Implementations Executive Regulations and Stand...
 
Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...
Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...
Towards the Implementation of the Sudan Interpolated Geoid Model Khartoum Sta...
 
Activating Geospatial Information for Sudans Sustainable Investment Map
Activating Geospatial Information for Sudans Sustainable Investment MapActivating Geospatial Information for Sudans Sustainable Investment Map
Activating Geospatial Information for Sudans Sustainable Investment Map
 
Educational Unity Embracing Diversity for a Stronger Society
Educational Unity Embracing Diversity for a Stronger SocietyEducational Unity Embracing Diversity for a Stronger Society
Educational Unity Embracing Diversity for a Stronger Society
 
Integration of Indian Indigenous Knowledge System in Management Prospects and...
Integration of Indian Indigenous Knowledge System in Management Prospects and...Integration of Indian Indigenous Knowledge System in Management Prospects and...
Integration of Indian Indigenous Knowledge System in Management Prospects and...
 
DeepMask Transforming Face Mask Identification for Better Pandemic Control in...
DeepMask Transforming Face Mask Identification for Better Pandemic Control in...DeepMask Transforming Face Mask Identification for Better Pandemic Control in...
DeepMask Transforming Face Mask Identification for Better Pandemic Control in...
 
Streamlining Data Collection eCRF Design and Machine Learning
Streamlining Data Collection eCRF Design and Machine LearningStreamlining Data Collection eCRF Design and Machine Learning
Streamlining Data Collection eCRF Design and Machine Learning
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 

Redux State Management System A Comprehensive Review

  • 1. International Journal of Trend in Scientific Research and Development (IJTSRD) Volume 6 Issue 7, November-December 2022 Available Online: www.ijtsrd.com e-ISSN: 2456 – 6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1021 Redux State Management System - A Comprehensive Review Krutika Patil Master of Science in Computer Science, The University of Texas at Dallas, Tracy, CA, USA ABSTRACT Reactivity is a common trait of JavaScript applications and comes with efficient state management. Any JavaScript application has multiple ways of managing state; for example, in React, we can use "useState” and “useReducer" Hooks. However, another third-party library called Redux has grown in popularity to be an efficient state management tool in JavaScript applications. This paper makes an in- depth review of the Redux state management system. It is famously used with React as a state-management tool and by other JavaScript frameworks as well. Redux is most suitable for applications with frequent updates to the state since Redux has better efficiency in a flux-like setup than React's Context API. KEYWORDS: ReactJs, Redux, state management, web development, JavaScript frameworks, React context, cross-component state, app- wide state, local state How to cite this paper: Krutika Patil "Redux State Management System - A Comprehensive Review" Published in International Journal of Trend in Scientific Research and Development (ijtsrd), ISSN: 2456- 6470, Volume-6 | Issue-7, December 2022, pp.1021- 1027, URL: www.ijtsrd.com/papers/ijtsrd52530.pdf Copyright © 2022 by author (s) and International Journal of Trend in Scientific Research and Development Journal. This is an Open Access article distributed under the terms of the Creative Commons Attribution License (CC BY 4.0) (http://creativecommons.org/licenses/by/4.0) INTRODUCTION Redux is a third-party JavaScript library. It has quickly gained recognition in the front-end world as the most efficient state-management system in an application with frequent state updates. It is a state- management system for cross-component and app- wide states. To understand the concept of various states, let us classify the different types of states. There are three states in a JavaScript application. Figure 1: Classification of States in a JavaScript application Local state - a state limited to a single component. For example, listening to a click event for a button or a user input for a text field. Usually handled in React applications bythe “useState” or the “useReducer” hook. Cross-component state - a state that affects multiple components. For example, opening and closing a modal overlay. In the case of a cross- component state, multiple components share the state. We achieve this state management using prop chains and prop drilling. App-wide state - affects the entire application or, at least, most components. One example of this could be the authentication status. Whether authenticated or not, the components might choose to hide, show, or update the content they render. We can use prop drilling and prop chains to achieve this state management. In the case of Cross-component and App-wide states, the "prop-drilling" and "prop-chaining" can get cumbersome since the props get passed around component hierarchies which might increase the chances of introducing defects in the logic. We can instead use the Redux library to manage the state for us in these cases. Redux maintains a central data store that the components can subscribe to and then IJTSRD52530
  • 2. International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1022 dispatch specific actions if the state needs to be updated. These concepts are depicted diagrammatically in Figure 1. CORE CONCEPTS OF REDUX A. Central Data Store Figure 2: Core Concepts of Redux Redux has a single central data store. Components can subscribe to a store to get any updates to the state or a part of the state. The components would also need a way to change the state. One important thing is that components never directly change or mutate a store. Instead, we use the Reducer function. B. Reducers A reducer is a programming concept. It is a function that is responsible for mutating or updating the store. A reducer is a pure function, meaning it should always produce the same output for the same input. We should not add side-effect logic (API calls or reading and writing to local storage) in the reducer functions. The components must use the reducers if they need to change or update the store. A reducer function always needs to be triggered by a component—for example, clicking a button or a user input on a text field. Hence, we need a way for components to do that. The concept of actions comes into play here. C. Actions The components dispatch or trigger actions, and the actions are JavaScript objects which include the description of the action and optionally contain a payload. The components dispatch these actions that contain a description of the intended action. The redux then forwards these actions to the reducer. The reducer reads the action description that describes the action and updates or mutates the state accordingly. We need to note here that components DO NOT directly update the store. Instead, the components dispatch actions, which get forwarded to the reducers. The reducer then spits a new state that replaces the existing state in the central data store. When the central state updates, the components that have subscribed to the store receive notifications instantly so that the components can update their UI. Figure 2 above describes in detail the concepts we discussed in this section. BASIC REDUX EXAMPLE IN JAVASCRIPT A. Setting up the central data store Consider the below script in Figure 3. Figure 3 Basic redux script in JavaScript Let us see the core concepts of Redux discussed in the previous section in action using the example above in Figure 3. First off, we import redux using the statement below in Figure 4. Figure 4 System to import redux in a JavaScript application The require("redux") expression returns a redux const that will be our Hook to the central data store. Next, let us create the central store on which the redux state management functionality depends. We can create a store using the statement below in Figure 5. Figure 5: Syntax to create a central data store in a JavaScript application
  • 3. International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1023 The function legacy_createStore returns a store object. The components subscribe to this store. It also takes in an argument which is our reducer. The reducer function mutates the store by spitting out a new state snapshot that replaces the previous one. Hence, this becomes the input to the legacy_createStore function. Next, let us look at the way to create a reducer. Consider the code below in Figure 6. A reducer is a JavaScript function. It takes in two arguments: state and action. The state is the current state snapshot and is forwarded to the reducer by redux. The second argument, "action”, is passed to the reducer by the components. This argument action contains a property type that describes the type of action. Based on the type of action, a particular state snapshot gets returned by the reducer. This state snapshot replaces the existing state in the central store. Figure 6 A typical redux reducer function Components can subscribe to the store using the function below in Figure 7. Figure 7 Subscriber function to a Redux store In the example above in Figure 7, the subscriber is a function that executes the logic to get the updates from the store using the store.getState(). As the state in the central store changes, the components subscribed to the store get notified instantly to update the UI. The components can update the state by dispatching specific actions using the logic in Figure 8. Figure 8 Logic to dispatch a Redux action We dispatch the action to increment the flag state in the above code. The dispatch function takes in an argument that is a JavaScript object and contains the type property. This property describes the type of action. We may also send a payload if we update the state to a specific value. Figure 9 A Redux Reducer function in JavaScript The dispatched action is forwarded to the reducer function by redux. An example of that is depicted above in Figure 9. We dispatch three actions in our script. store.dispatch({type: 'increment'}); store.dispatch({type: 'increment'}); store.dispatch({type: 'increment', payload: 50}); Hence, our output would be as depicted in Figure 10. The first output is for the action increment that increases the flag value to 1 from its initial value of 0. The second output is for the dispatched action decrement that decrements the flag value to 0 from 1. Furthermore, the third value is due to the action "incrementBy", which also contained a payload of 50. The action increments the flag by 50 from 0. Figure 10 Output of the script depicted in Figure 3 USING REDUX IN A REACT APPLICATION Consider a simple react project below in Figure 11. It prints out the value of the flag that is initially 0. There are four buttons to perform various operations that we will cover soon. Figure 11 A simple React App Let us now install redux into the application. To do that, we need to get the reduxjs/toolkit, a third-party package that makes working with redux very easy. The command to install redux is depicted below in Figure 12.
  • 4. International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1024 Figure 12 Command to install reduxjs/toolkit library in a React Application. Next, we will install react-redux, another package that gives us access to libraries responsible for dispatching actions and subscribing to a store. The syntax is depicted below in Figure 13. Figure 13 Command to install react-redux in a React Application. Once done, let us go ahead and create our central store that stores the state. A vital feature given by the redux toolkit is that we can have slices of the state. We can split the state into two slices for our current React application in Figure 11. A UI Slice manages the state to display or hide the flag; a Flag Slice could maintain the flag state. Let us start by creating the UI Slice. We must import the createSlice library from the redux toolkit to create our slice script. Figure 14 depicts the syntax. Figure 14 Syntax to import createSlice hook function from reduxjs/toolkit The createSlice is a function. It takes in an object with the following three properties: a name property that uniquely identifies the state slice, an initialState property with which the state gets initialized, and the reducers property where we can list the various actions supported by this slice. The logic to create a state slice looks as below in Figure 15. Figure 15 Logic to create a state slice to toggle the flag visibility Here, the reducers property is, in turn, an object with various actions that are supported. We see that toggleFlag modifies the state by flipping the previous value. We notice here that the initial state is true. Similarly, let us also create the flagSlice. We will have three actions in the flagSlice as supported by the reducer. The export flagSlice.reducer gives us access to this reducer. The components use the export "flagActions" to dispatch various actions. Our next step is to configure these reducers in our store. Let us create a new script file and import configureStore from reduxjs/toolkit. The syntax is depicted below in Figure 16. Figure 16 Syntax to import configureStore from reduxjs/toolkit This function configureStore takes in an argument which is a JavaScript object. This JavaScript object needs to list out the reducers. We can achieve this by adding an object with property reducers, and its value could be another object with any key that the user prefers and its value being a reducer. Below in Figure 17, we have configured both the reducers into the store. Figure 17 Configuring a Redux store in React by combining multiple state slices. The store needs to be made available to the entire application. We can do this in the index.js file in the root folder. Import the store from the store folder. We also need to import Provider from the react-redux library. The Provider is a React element, and by wrapping it around our main App component, we will make the store available to the app. The Provider element takes in a prop, the store object imported from the redux script. The code looks like the one below in Figure 18.
  • 5. International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1025 Figure 18 Making the Redux store available to the entire application Following the above steps, we successfully set up our React application with Redux. The following section discusses how to dispatch an action on the store and subscribe to the store. B. Dispatching Actions to the central data store The components need to import the “useDispatch” Hook from react-redux. This Hook, when executed, gives us a dispatch constant that we can use to trigger our actions. The logic to import useDispatch Hook is as below in Figure 19. Figure 19 Syntax to import the useDispatch Hook from react-redux library Execute the useDispatch Hook inside the component to retrieve a dispatch constant, as depicted in Figure 20. Figure 20 Executing useDispatch Hook to retrieve a dispatch constant. Next, we would like to dispatch specific actions when clicking the buttons. For example, the Toggle Flag button will show or hide the flag. The Increment button will increment the flag. The Decrement button will decrement the flag. Furthermore, we need to increment the flag by a certain number upon clicking the "Increment By 10" button. For this, let us import the actions from our reducer scripts. The syntax is depicted below in Figure 21. Figure 21 Importing the Reducer actions from the Reducer scripts Let us consider clicking on the button Toggle Flag. We want to show or hide the flag when clicking this button. We essentially dispatch the action “toggleFlag" in this case which gets forwarded to the Reducer by Redux. The syntax is depicted below in Figure 22. Figure 22 Dispatching a Redux Action from a component The function toggleFlagHandler dispatches the toggleFlag action, and as we know, the toggleFlag action in the uiActions reducer flips the showFlag state. Similarly, consider incrementing the flag by clicking on the Increment button. The button's onClick handler executes the incrementHandler function that dispatches the incrementFlag action. We have depicted the same in Figure 23. Figure 23 Dispatching increment Flag, decrement Flag and increment By actions C. Subscribing to the store The components need to import the "useSelector” Hook from the react-redux library to get updates from the store. The import syntax is depicted below in Figure 24. When the central state in the store updates, the subscribing components get updated instantly. Figure 24 Syntax to import “useSelector” Hook from ‘react-redux’ library We need to execute the "useSelector" Hook inside the components only. It takes in an argument that is a state and returns the specific state that we need. The logic looks like below. When we set up our store, we added keys to the specific reducers ui and flag. Hence, while retrieving the state, we need to use these keys to refer to a state of our choice. We have depicted the same in Figure 25. Figure 25 Syntax to retrieve the state from the store
  • 6. International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1026 The retrieved state showFlag updates whenever the state.ui.showFlag changes, thereby re-rendering the component. The exact mechanism applies to the other buttons that trigger their actions, resulting in reducers performing appropriate state updates based on the action types. RESULTS The initial state of the UI is depicted below in Figure 26. Figure 26 Initial state of the UI Below are the results on the UI due to clicking on Increment, Decrement, Increment By 10, and Toggle Flag buttons, respectively. These are depicted respectively in Figure 27 - 30. The first action triggered due to a click event on the "Increment” button is the “incrementFlag" action. The initial state 0 of the "flag" got updated to 1. The second action triggered due to a click event on the "Decrement” button is the “decrementFlag" action. The initial state 1 of the "flag" got updated to 0. The third action triggered due to a click event on the "Increment By 10” button is the “incrementBy” action. The initial state 0 of the "flag" got updated to 50. The fourth action triggered due to a click event on the "ToggleFlag” button is the “toggleFlag” action. With the initial state of the “showFlag” state in the store being “true", it was updated to “false”. Since the components have subscribed to the store, the updates are reflected on the UI instantaneously. Figure 27 UI State after clicking on the “Increment” button Figure 28 UI State after clicking on the “Decrement” button Figure 29 UI State after clicking on the “Increment By 10” button Figure 30 UI State after clicking on the “Toggle Flag” button CONCLUSION This paper attempts to dive deep into the features of the Redux state management mechanism. We started with understanding managing the state in an application and looked at various aspects of Redux, like the central data store, actions, and reducers. Also, we discussed the subscription mechanism of the components to the store to get instant updates. We looked at how we can split the state into multiple slices that serve a specific purpose. The reducers can update the slices only, and behind the scenes, the Redux will combine the state snapshot into the overall state. The feature of Redux discussed in this paper helps us de-clutter the logic into respective scripts and helps make the code easy to maintain. The Redux statement system can be a good option in a flux-like system with frequent updates to the state. REFERENCES [1] Krutika Patil, Sanath DhananjayamurtyJavagal, "React state management and side-effects – A Review of Hooks", IRJET Journal, volume 9, 2022, https://www.irjet.net/archives/V9/i12/IRJET- V9I1225.pdf. [2] https://www.udemy.com/course/react-the- complete-guide-incl- redux/learn/lecture/25599228?start=405#overvi ew [3] Shravan G V, Anitha Sandeep. "COMPREHENSIVEANALYSISOFREACT- REDUX DEVELOPMENT FRAMEWORK", International Journal of Creative Research Thoughts (IJCRT), ISSN:2320-2882, Vol.8, Issue 4, pp.4230-4233, April 2020, URL: http://www.ijcrt.org/IJCRT2004607 [4] Banks, Alex, and Eve Porcello. Learning React: functional web development with React and Redux. " O'Reilly Media, Inc.", 2017. [5] Caspers, Matthias Kevin. "React and redux." Rich Internet Applications w/HTML and Javascript 11 (2017).
  • 7. International Journal of Trend in Scientific Research and Development @ www.ijtsrd.com eISSN: 2456-6470 @ IJTSRD | Unique Paper ID – IJTSRD52530 | Volume – 6 | Issue – 7 | November-December 2022 Page 1027 [6] Chinnathambi, Kirupa. Learning React: A Hands-on Guide to Building Web Applications Using React and Redux. Addison-Wesley Professional, 2018. [7] McFarlane, Timo. "Managing State in React Applications with Redux." (2019). [8] Roldan, Carlos Santana. React Cookbook: Create dynamic web apps with React using Redux, Webpack, Node. js, and GraphQL. Packt Publishing Ltd, 2018. [9] Bugl, Daniel. Learning Redux. Packt Publishing Ltd, 2017. [10] Pronina, Daria, and Iryna Kyrychenko. "Comparison of Redux and React Hooks Methods in Terms of Performance." Proceedings http://ceur-ws. org ISSN 1613 (2022): 0073