react redux.pdf

2,027 views 21 slides Oct 04, 2022
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

This session will be about maintaning the store on client side with redux, And will have more details about state management addressing single source of truth concept


Slide Content

Presented By: Pushpendra Sharma
& Umang Goyal
Introduction to
React-Redux

Lack of etiquette and manners is a huge turn off.

Knolx Etiquettes
Punctuality
Respect session timings, you
are requested not to join
sessions after a 5 minutes
threshold post the session
start time.
Feedback
Make sure to submit a
constructive feedback for all
sessions as it is very helpful
for the presenter.
Silent Mode
Keep your mobile devices in
silent mode, feel free to move
out of session in case you need
to attend an urgent call.
Avoid Disturbance
Avoid unwanted chit chat
during the session.

Agenda
Anatomy of modern webapp



01
02
03
04
05
How React Redux
Benefits of using Redux
What is State Management
How to Redux works
06 How to use Redux with React ( Demo )

Anatomy of Modern Webapp
❖It a single page application, means should update UI dynamically with the
data fetched from server without re-loading the page
❖It should be fast and frictionless experience

Architecture of modern webapp
❖Instead of creating pages, components are build first and then are composed in
complex UIs.
❖Data is passed into those components and it takes care of how to update the UI.
❖Data is kept out of the component tree so that its not affected by re-renders of UI,
its centralised and consistent.
❖A state management solution to manage data independent of the UI layer.

Architecture of Modern Webapp
user: {
email,
token,
},

transaction: {
data,
page,
},
account: {
isAdmin,
privileges,
}
Component tree
Data

What is State Management
It is exactly as it sounds, managing state of the application.
State:
➔Data fetched from server.
➔User details, tokens, role.
➔Details filled in the forms.
➔etc
Management:
➔Initializing
➔Updating
➔Deleting

Why is State Management required
❖A centralised data state
❖Consistent data available across applications to all pages and components (
header, table, graphs, menus ).
❖Data is readily available and updated on the client side instead of requesting
from server each time.

Why is State Management required
( login )
( navigate,
view feeds )
( update
details )
( select user
options )
( user details )
( user details )
( transaction,
user details etc )
( user details )
( transaction )
Event
Data

Why is State Management required
( login )
( navigate,
view feeds )
( update
details )
( select user
options )
( user details )
( feeds )
( transaction )
( .
.
. )
Event
Data

Why is State Management required
( login )
( navigate,
view feeds )
( update
details )
( select user
options )
( user details )
( feeds )
( transaction )
( .
.
. )
Event
Data

React
❖Javascript library
❖Used to build UI components, especially for a single page application.

Redux
❖Javascript library
❖Used for state management in Javascript apps.
❖Works independently of UI library.


What is React Redux

How Redux works
View
ActionReducer
Store(cent
ral State)
Selector
Redux is a predictable, centralised, debuggable and flexible state container
for JS apps.

How Redux works
View
ActionReducer
Store
Selector
Store is the state object which is maintained by redux. It’s a simple
javascript object.
Button
user: {
email,
token,
},
transaction: {
data,
page,
},
poins: {
score,
history
},
account: {
isAdmin,
privileges,
}
Store ( State Object )

How Redux works
View
ActionReducer
Store
Selector
Action is simple JS object that should a “type” key and can also have a
“payload” key. Passed into a dispatcher function

Button
{
type: ‘ADD_TASK’,
payload: {
name: ‘buy milk’,
done: false,
}
}
Action
dispatcher()
Event

How Redux works
View
ActionReducer
Store
Selector
Reducer is a pure JS function that takes current state and action as
arguments and returns the updated state.
Redux only has one root reducer.

Button
function ({
state, action
}) => {
case: ‘ADD_TASK’
return {
…state,
task: action.payload
}
case: ‘DELETE_TASK’
return {
…state,
task: action.payload
}
}
Reducer

How Redux works
View
ActionReducer
Store
Selector
Selector is a pure JS function that takes current state and returns a slice of
the store object. It re-evaluates its output when store
is updated and view can subscribe to it..

Button
function (state) => {
return state.tasks
}
Selector

Benefits of using Redux with React

❖Predictable flow of data
❖Centralised data store
❖Debuggable, due to availability of redux dev-tools
❖Leaner react components

Demo

●https://reactjs.org/docs/getting-started.html
●https://redux.js.org/
References

Thank You !
Get in touch with us: