SlideShare a Scribd company logo
1 of 25
reactJs
State management
State management (contd.)
Store
State management (contd.)
FluxJS RefluxJS ReduxJ
S
MobXJS
State management (contd.)
Redux
 Motivation
 Lost control over the when, why, and how of its state.
 Single Source of truth is to hard to maintain.
 Hard to reproduce bugs or add new features.
 Handle optimistic updates, server-side rendering, fetching data before performing route transitions will be
impossible.
State management (contd.)
Action Store
UI
State management (contd.)
Action Reducer Store
UI
State management (contd.)
Three Principles
 Single source of truth.
 State is read-only.
 The only way to change the state is to emit an action, an object describing (action.type) what
happened.
 This ensures that neither the views nor the network callbacks will ever write directly to the state.
 Changes are made with pure functions
 Reducers are just pure functions that take the previous state and an action, and return the next state.
State management (contd.)
Action Creator
UI
Dispatch
Calculate and return
new store
Redux
Broadcast The Action
Object and the current
store
Reducer
Reducer
Reducer
Reducer
ReduxStore
Send the new store
to save it
Send Action Object
Send the new state
for updating
State management (contd.)
Action Creators & Actions
 Actions are payloads of information that send data from your application to your store.
 The only source of information for the store.
 You send them to the store using store.dispatch() as it dispatch Action Creator.
State management (contd.)
Reducer
 Specify how the application's state changes in response to actions sent to the store.Normal (Pure) function
 Computes only the new state.
 Should be completely predictable: calling it with the same inputs many times should produce the same outputs.
 Shouldn't perform any side effects like API calls or router transitions.
 You cannot update in state directly, you create a new object using Object.assign({}, state) then return it and the
redux will handle how to update the store.
 You can split the reducer to sub-reducers to so you can maintain it easily then you can combine them
State management (contd.)
Reducer
State management (contd.)
Store
 You'll only have a single store in a Redux application.
 If You want to split your data handling logic, you'll use reducer composition instead of many stores.
 New Reducer = New Store
 The store has the following responsibilities:
 Holds application state;
Allows access to state via getState();
Allows state to be updated via dispatch(action)
State management (contd.)
Middleware
 Redux middleware is nothing more than a function which is invoked after an action is dispatched but before a reducer takes care of
the action.
 Middleware are functions that allow us extend the functionality of our redux application.
State management (contd.)
Broadcast The Action
Object and the current
store
on Creator
Send Action Object
Redu
Middleware#1
Middleware#2
Middleware#3
Middleware#4
State management (contd.)
Middleware
(Activity) State management (contd.)
(Activity):
Write a sum method which will work properly when
invoked using either syntax below:
console.log(sum(2,3)) //5
console.log(sum(2)(3)) //5
(Activity) State management (contd.)
(Activity) State management (contd.)
(Activity) State management (contd.)
TITLE HERE
Subtitle Here
Phenomenon whereby something
new and somehow valuable is formed
the created item may be intangible
such as an idea or a physical object
such as an invention, a literary work
Phenomenon whereby something
new and somehow valuable is formed
the created item may be intangible
such as an idea or a physical object
such as an invention, a literary work
Phenomenon whereby something
new and somehow valuable is formed
the created item may be intangible
such as an idea or a physical object
such as an invention, a literary work
LOREM IPSUM
DOLOR
LOREM IPSUM
DOLOR
LOREM IPSUM
DOLOR
Programmer Graphic
Designer
Author
TITLE HERE
TITLE HERE
Lorem ipsum dolor
sit amet, animal
conceptam te his,
Lorem ipsum dolor
sit amet, animal
conceptam te his,
Lorem ipsum dolor
sit amet, animal
conceptam te his,
Lorem ipsum dolor
sit amet, animal
conceptam te his,
TITLE HERE TITLE HERE TITLE HERE TITLE HERE
Lorem ipsum dolor sit amet, animal
conceptam te his, legimus inimicus dissentiet
at sed, cum an idque possit percipitur. Reque
accusamus has cu. Eam ex eros utinam, ut
alii saepe dignissim usu.
TITLE HERE
Lorem ipsum dolor sit amet, animal
conceptam te his, legimus inimicus dissentiet
at sed, cum an idque possit percipitur. Reque
accusamus has cu. Eam ex eros utinam, ut
alii saepe dignissim usu.
TITLE HERE
Lorem ipsum dolor sit amet, animal
conceptam te his, legimus inimicus dissentiet
at sed, cum an idque possit percipitur. Reque
accusamus has cu. Eam ex eros utinam, ut
alii saepe dignissim usu.

More Related Content

Similar to ReactJs State Management Redux

React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with ReduxVedran Blaženka
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Cesar Valiente "Unidirectional architecture on Android with Kotlin"
Cesar Valiente "Unidirectional architecture on Android with Kotlin"Cesar Valiente "Unidirectional architecture on Android with Kotlin"
Cesar Valiente "Unidirectional architecture on Android with Kotlin"IT Event
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of ReduxInnovationM
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to ReduxAmin Ashtiani
 
Let's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptMathieu Savy
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тягаVitebsk Miniq
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Reviewijtsrd
 
Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Nir Kaufman
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxCommit University
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptxNavneetKumar111924
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareVisual Engineering
 
Workshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedVisual Engineering
 

Similar to ReactJs State Management Redux (20)

Reducers+flux=redux
Reducers+flux=reduxReducers+flux=redux
Reducers+flux=redux
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
Understanding redux
Understanding reduxUnderstanding redux
Understanding redux
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Cesar Valiente "Unidirectional architecture on Android with Kotlin"
Cesar Valiente "Unidirectional architecture on Android with Kotlin"Cesar Valiente "Unidirectional architecture on Android with Kotlin"
Cesar Valiente "Unidirectional architecture on Android with Kotlin"
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
Let's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScript
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Review
 
Redux
ReduxRedux
Redux
 
Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016
 
React
ReactReact
React
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
 
State of the state
State of the stateState of the state
State of the state
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016
 
Redux js
Redux jsRedux js
Redux js
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Workshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux Advanced
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 

ReactJs State Management Redux

  • 4. State management (contd.) FluxJS RefluxJS ReduxJ S MobXJS
  • 5. State management (contd.) Redux  Motivation  Lost control over the when, why, and how of its state.  Single Source of truth is to hard to maintain.  Hard to reproduce bugs or add new features.  Handle optimistic updates, server-side rendering, fetching data before performing route transitions will be impossible.
  • 8. State management (contd.) Three Principles  Single source of truth.  State is read-only.  The only way to change the state is to emit an action, an object describing (action.type) what happened.  This ensures that neither the views nor the network callbacks will ever write directly to the state.  Changes are made with pure functions  Reducers are just pure functions that take the previous state and an action, and return the next state.
  • 9. State management (contd.) Action Creator UI Dispatch Calculate and return new store Redux Broadcast The Action Object and the current store Reducer Reducer Reducer Reducer ReduxStore Send the new store to save it Send Action Object Send the new state for updating
  • 10. State management (contd.) Action Creators & Actions  Actions are payloads of information that send data from your application to your store.  The only source of information for the store.  You send them to the store using store.dispatch() as it dispatch Action Creator.
  • 11. State management (contd.) Reducer  Specify how the application's state changes in response to actions sent to the store.Normal (Pure) function  Computes only the new state.  Should be completely predictable: calling it with the same inputs many times should produce the same outputs.  Shouldn't perform any side effects like API calls or router transitions.  You cannot update in state directly, you create a new object using Object.assign({}, state) then return it and the redux will handle how to update the store.  You can split the reducer to sub-reducers to so you can maintain it easily then you can combine them
  • 13. State management (contd.) Store  You'll only have a single store in a Redux application.  If You want to split your data handling logic, you'll use reducer composition instead of many stores.  New Reducer = New Store  The store has the following responsibilities:  Holds application state; Allows access to state via getState(); Allows state to be updated via dispatch(action)
  • 14. State management (contd.) Middleware  Redux middleware is nothing more than a function which is invoked after an action is dispatched but before a reducer takes care of the action.  Middleware are functions that allow us extend the functionality of our redux application.
  • 15. State management (contd.) Broadcast The Action Object and the current store on Creator Send Action Object Redu Middleware#1 Middleware#2 Middleware#3 Middleware#4
  • 17. (Activity) State management (contd.) (Activity): Write a sum method which will work properly when invoked using either syntax below: console.log(sum(2,3)) //5 console.log(sum(2)(3)) //5
  • 22. Phenomenon whereby something new and somehow valuable is formed the created item may be intangible such as an idea or a physical object such as an invention, a literary work Phenomenon whereby something new and somehow valuable is formed the created item may be intangible such as an idea or a physical object such as an invention, a literary work Phenomenon whereby something new and somehow valuable is formed the created item may be intangible such as an idea or a physical object such as an invention, a literary work LOREM IPSUM DOLOR LOREM IPSUM DOLOR LOREM IPSUM DOLOR Programmer Graphic Designer Author TITLE HERE
  • 23. TITLE HERE Lorem ipsum dolor sit amet, animal conceptam te his, Lorem ipsum dolor sit amet, animal conceptam te his, Lorem ipsum dolor sit amet, animal conceptam te his, Lorem ipsum dolor sit amet, animal conceptam te his, TITLE HERE TITLE HERE TITLE HERE TITLE HERE
  • 24. Lorem ipsum dolor sit amet, animal conceptam te his, legimus inimicus dissentiet at sed, cum an idque possit percipitur. Reque accusamus has cu. Eam ex eros utinam, ut alii saepe dignissim usu. TITLE HERE
  • 25. Lorem ipsum dolor sit amet, animal conceptam te his, legimus inimicus dissentiet at sed, cum an idque possit percipitur. Reque accusamus has cu. Eam ex eros utinam, ut alii saepe dignissim usu. TITLE HERE Lorem ipsum dolor sit amet, animal conceptam te his, legimus inimicus dissentiet at sed, cum an idque possit percipitur. Reque accusamus has cu. Eam ex eros utinam, ut alii saepe dignissim usu.