SlideShare a Scribd company logo
Front End Workshops
Redux Advanced
Enrique Oriol
eoriol@naradarobotics.com
Alex Adrià
aadria@visual-engin.com
Workshop 22: ReactJS Redux Advanced
Previously in ReactJS...
ReactJS Basics
1. Decompose UI into reusable components which
render to virtual DOM
2. ReactJS will sync VDOM to real browser DOM
3. JSX format
4. Can render on client and server
Previously in ReactJS...
Redux
PATTERNS
FLUX
CQRS
EVENT SOURCING
PRINCIPIOS
SINGLE SOURCE OF TRUTH
READ-ONLY STATE
CHANGES WITH PURE
FUNCTIONS
Previously in ReactJS...
Redux
React Action Creator
Action
Reducers
State
Calls Returns
Sent to
Creates new
Sent to
Previously in ReactJS...
React-router
React
History
React router
Higher Order Components
(HOC)
What is a HOC?
● It is a JavaScript function which is used for adding
additional functionality to existing component
● A takes an existing component and returns another
component that wraps it.
● If the HOC data changes, It will re-run again and update
the resulting component.
● It usually contains reusable common behaviours
resulting in simpler and better structured components.
● A component can be wrapped several times by multiple
wrappers.
Decorator Pattern
Decorator Pattern
export default function(ComposedComponent) {
class HOCExample extends Component {
componentDidMount() {
this.setState({data:'Data from HOC...'});
}
render() {
return <ComposedComponent {...this.props} {...this.state} />;
}
}
return HOCExample;
}
HOC structure example
Redux Middleware
What is middleware
Provides capability to
put CODE
between
dispatching an action
and
reaching the reducer.
Basic redux life-cycle
React Action Creator
Action
Reducers
State
Calls Returns
Sent to
Creates new
Sent to
Redux life-cycle with middlewares
Middleware
React Action Creator
Action
Reducers
State
Calls Returns
Sent to
Forwards
action to
Creates new
Sent to Middleware receives
the action
and can log
stop and modify it
Middleware benefits
COMPOSABLE
INDEPENDENT
Middleware stack example 1
Middleware # 1
I don’t care about this action, I’ll send it
to the NEXT middleware
Action Creator Action
Reducers
next
Middleware # 2
I will log this action, and move it
forward
Middleware # 3
I don’t care about this action, I’ll send it
to the NEXT middleware
next
console.log()
Middleware structure
● It is a function that receives the store
● It MUST return a function with arg “next”
● That returns a function with arg “action”
○ Where we do our stuff
○ And return
■ next(action)
■ state.dispatch(action)
export default function(store){
return function(next){
return function(action){
//do something
//use next(action) or
//state.dispatch(action)
}
}
}
Middleware structure
ES 5 middleware declaration
export default store => next => action => {
//do something
//next(action); or state.dispatch(action);
}
}
Middleware structure ES6
export default ({dispatch}) => next => action => {
//our stuff
}
}
src/middleware/myMiddleware.js
In case we don’t need the store
Middleware
C’MON MAN!
GIVE ME an EXAMPLE!!
Simplest example - logger
Middleware
REACT IncreaseCounter() INC_ACTION
ReducersSTATE
- counter
Forwards
action to
Component
counter
+
- DecreaseCounter()
DEC_ACTION
Update
state
counter
logger
Using our middleware
import {createStore, applyMiddleware } from 'redux';
import reducers from './reducers';
import MyMid from './middlewares/my-middleware';
const createStoreWithMiddleware = applyMiddleware(myMid)(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>
, document.querySelector('.container'));
src/index.js
Modify action middleware workflow
Middleware that modifies specific
action
Is it the action that I want?
Action Creator Action
no yes
Send action
forwards
Next middleware
Do some
stuff
Create new action
with the results Action
Middleware
stack
next(action)
store.dispatch(newAction)
Middleware
CAN YOU
SHOW ME
SOME CODE?
Dispatch action example - superstitious counter
Middleware
REACT IncreaseCounter() INC_ACTION
ReducersSTATE
- counter
Forwards
action to
Component
counter
+
- DecreaseCounter()
DEC_ACTION
Update
state
counter
logger
superstitious
Popular middlewares
redux-promise
redux-thunk
Redux-logger
Remember: npm install --save package
Thanks for your time!
Do you have any questions?
Workshop 22: ReactJS Redux Advanced

More Related Content

What's hot (20)

PPTX
Introduction to React JS
Arnold Asllani
 
PPTX
Intro to React
Justin Reock
 
PDF
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
PDF
Android Jetpack
Tudor Sirbu
 
PPTX
reactJS
Syam Santhosh
 
PPT
React native
Mohammed El Rafie Tarabay
 
PDF
Workshop 21: React Router
Visual Engineering
 
PDF
Intro to vue.js
TechMagic
 
PPTX
Server side rendering review
Vladyslav Morzhanov
 
PDF
Struts presentation
Nicolaescu Petru
 
PDF
Understanding react hooks
Samundra khatri
 
PDF
Angular Advanced Routing
Laurent Duveau
 
PPTX
Django PPT.pptx
KhyatiBandi1
 
PPTX
React workshop presentation
Bojan Golubović
 
PDF
Introduction to ReactJS
Hoang Long
 
PPTX
Typescript ppt
akhilsreyas
 
PPTX
React js
Alireza Akbari
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PDF
Getting started with Next.js
Gökhan Sarı
 
PDF
Introduction to Spring's Dependency Injection
Richard Paul
 
Introduction to React JS
Arnold Asllani
 
Intro to React
Justin Reock
 
Redux Toolkit - Quick Intro - 2022
Fabio Biondi
 
Android Jetpack
Tudor Sirbu
 
reactJS
Syam Santhosh
 
Workshop 21: React Router
Visual Engineering
 
Intro to vue.js
TechMagic
 
Server side rendering review
Vladyslav Morzhanov
 
Struts presentation
Nicolaescu Petru
 
Understanding react hooks
Samundra khatri
 
Angular Advanced Routing
Laurent Duveau
 
Django PPT.pptx
KhyatiBandi1
 
React workshop presentation
Bojan Golubović
 
Introduction to ReactJS
Hoang Long
 
Typescript ppt
akhilsreyas
 
React js
Alireza Akbari
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Getting started with Next.js
Gökhan Sarı
 
Introduction to Spring's Dependency Injection
Richard Paul
 

Viewers also liked (20)

PDF
Introduction to ReactJS
Tu Hoang
 
PDF
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
PDF
panduan-google-adsense.pdf
SMK Negeri 6 Malang
 
PPTX
004. Working with React component
Binh Quan Duc
 
PPT
Starting with Reactjs
Thinh VoXuan
 
PPTX
002. Working with Webpack
Binh Quan Duc
 
PPTX
001. Introduction about React
Binh Quan Duc
 
PPTX
005. a React project structure
Binh Quan Duc
 
PPTX
006. React - Redux framework
Binh Quan Duc
 
PDF
Redux with angular 2 - workshop 2016
Nir Kaufman
 
PPTX
003. ReactJS basic
Binh Quan Duc
 
PDF
Using ReactJS in AngularJS
Boris Dinkevich
 
PPTX
007. Redux middlewares
Binh Quan Duc
 
PDF
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
PPTX
Angular 2 - Better or worse
Vladimir Georgiev
 
PDF
Angular 2 for Java Developers
Yakov Fain
 
PDF
Angular 2 Essential Training
Patrick Schroeder
 
PDF
Reactive programming in Angular 2
Yakov Fain
 
PPTX
Introduction to angular 2
Dor Moshe
 
PPTX
Angular 4 - quick view
Michael Haberman
 
Introduction to ReactJS
Tu Hoang
 
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
panduan-google-adsense.pdf
SMK Negeri 6 Malang
 
004. Working with React component
Binh Quan Duc
 
Starting with Reactjs
Thinh VoXuan
 
002. Working with Webpack
Binh Quan Duc
 
001. Introduction about React
Binh Quan Duc
 
005. a React project structure
Binh Quan Duc
 
006. React - Redux framework
Binh Quan Duc
 
Redux with angular 2 - workshop 2016
Nir Kaufman
 
003. ReactJS basic
Binh Quan Duc
 
Using ReactJS in AngularJS
Boris Dinkevich
 
007. Redux middlewares
Binh Quan Duc
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Paweł Żurowski
 
Angular 2 - Better or worse
Vladimir Georgiev
 
Angular 2 for Java Developers
Yakov Fain
 
Angular 2 Essential Training
Patrick Schroeder
 
Reactive programming in Angular 2
Yakov Fain
 
Introduction to angular 2
Dor Moshe
 
Angular 4 - quick view
Michael Haberman
 
Ad

Similar to Workshop 22: ReactJS Redux Advanced (20)

PDF
A React Journey
LinkMe Srl
 
PPTX
Redux
Maulik Shah
 
PPTX
Redux workshop
Imran Sayed
 
PPTX
React + Flux = Joy
John Need
 
PDF
Redux Deep Dive - ReactFoo Pune 2018
Aziz Khambati
 
PDF
The Road To Redux
Jeffrey Sanchez
 
PDF
Building React Applications with Redux
FITC
 
PPTX
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
PDF
Getting started with React and Redux
Paddy Lock
 
PPTX
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
PDF
Redux js
Nils Petersohn
 
PDF
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Mateusz Bosek
 
PDF
Intro to Redux | DreamLab Academy #3
DreamLab
 
PDF
How to Redux
Ted Pennings
 
PDF
Egghead redux-cheat-sheet-3-2-1
Augustin Bralley
 
PDF
Redux tutorial - intro to Redux by GetLittleTech
Oleg Kosuchin (GetLittleTech)
 
PDF
React & Redux
Federico Bond
 
PDF
An Overview of the React Ecosystem
FITC
 
PPTX
Redux Tech Talk
Chathuranga Jayanath
 
PDF
Building Modern Web Applications using React and Redux
Maxime Najim
 
A React Journey
LinkMe Srl
 
Redux workshop
Imran Sayed
 
React + Flux = Joy
John Need
 
Redux Deep Dive - ReactFoo Pune 2018
Aziz Khambati
 
The Road To Redux
Jeffrey Sanchez
 
Building React Applications with Redux
FITC
 
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Getting started with React and Redux
Paddy Lock
 
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
Redux js
Nils Petersohn
 
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Mateusz Bosek
 
Intro to Redux | DreamLab Academy #3
DreamLab
 
How to Redux
Ted Pennings
 
Egghead redux-cheat-sheet-3-2-1
Augustin Bralley
 
Redux tutorial - intro to Redux by GetLittleTech
Oleg Kosuchin (GetLittleTech)
 
React & Redux
Federico Bond
 
An Overview of the React Ecosystem
FITC
 
Redux Tech Talk
Chathuranga Jayanath
 
Building Modern Web Applications using React and Redux
Maxime Najim
 
Ad

More from Visual Engineering (20)

PDF
Workshop 27: Isomorphic web apps with ReactJS
Visual Engineering
 
PDF
Workshop iOS 4: Closures, generics & operators
Visual Engineering
 
PDF
Workshop iOS 3: Testing, protocolos y extensiones
Visual Engineering
 
PDF
Workshop iOS 2: Swift - Structures
Visual Engineering
 
PDF
Workhop iOS 1: Fundamentos de Swift
Visual Engineering
 
PDF
Workshop 26: React Native - The Native Side
Visual Engineering
 
PDF
Workshop 25: React Native - Components
Visual Engineering
 
PDF
Workshop 24: React Native Introduction
Visual Engineering
 
PDF
Workshop 22: React-Redux Middleware
Visual Engineering
 
PDF
Workshop 20: ReactJS Part II Flux Pattern & Redux
Visual Engineering
 
PDF
Workshop 19: ReactJS Introduction
Visual Engineering
 
PDF
Workshop 18: CSS Animations & cool effects
Visual Engineering
 
PDF
Workshop 17: EmberJS parte II
Visual Engineering
 
PDF
Workshop 16: EmberJS Parte I
Visual Engineering
 
PDF
Workshop 15: Ionic framework
Visual Engineering
 
PDF
Workshop 14: AngularJS Parte III
Visual Engineering
 
PDF
Workshop 13: AngularJS Parte II
Visual Engineering
 
PDF
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PDF
Workshop 11: Trendy web designs & prototyping
Visual Engineering
 
Workshop 27: Isomorphic web apps with ReactJS
Visual Engineering
 
Workshop iOS 4: Closures, generics & operators
Visual Engineering
 
Workshop iOS 3: Testing, protocolos y extensiones
Visual Engineering
 
Workshop iOS 2: Swift - Structures
Visual Engineering
 
Workhop iOS 1: Fundamentos de Swift
Visual Engineering
 
Workshop 26: React Native - The Native Side
Visual Engineering
 
Workshop 25: React Native - Components
Visual Engineering
 
Workshop 24: React Native Introduction
Visual Engineering
 
Workshop 22: React-Redux Middleware
Visual Engineering
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Visual Engineering
 
Workshop 19: ReactJS Introduction
Visual Engineering
 
Workshop 18: CSS Animations & cool effects
Visual Engineering
 
Workshop 17: EmberJS parte II
Visual Engineering
 
Workshop 16: EmberJS Parte I
Visual Engineering
 
Workshop 15: Ionic framework
Visual Engineering
 
Workshop 14: AngularJS Parte III
Visual Engineering
 
Workshop 13: AngularJS Parte II
Visual Engineering
 
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
Workshop 11: Trendy web designs & prototyping
Visual Engineering
 

Recently uploaded (20)

PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Import Data Form Excel to Tally Services
Tally xperts
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 

Workshop 22: ReactJS Redux Advanced

  • 3. Previously in ReactJS... ReactJS Basics 1. Decompose UI into reusable components which render to virtual DOM 2. ReactJS will sync VDOM to real browser DOM 3. JSX format 4. Can render on client and server
  • 4. Previously in ReactJS... Redux PATTERNS FLUX CQRS EVENT SOURCING PRINCIPIOS SINGLE SOURCE OF TRUTH READ-ONLY STATE CHANGES WITH PURE FUNCTIONS
  • 5. Previously in ReactJS... Redux React Action Creator Action Reducers State Calls Returns Sent to Creates new Sent to
  • 8. What is a HOC? ● It is a JavaScript function which is used for adding additional functionality to existing component ● A takes an existing component and returns another component that wraps it. ● If the HOC data changes, It will re-run again and update the resulting component. ● It usually contains reusable common behaviours resulting in simpler and better structured components. ● A component can be wrapped several times by multiple wrappers.
  • 11. export default function(ComposedComponent) { class HOCExample extends Component { componentDidMount() { this.setState({data:'Data from HOC...'}); } render() { return <ComposedComponent {...this.props} {...this.state} />; } } return HOCExample; } HOC structure example
  • 13. What is middleware Provides capability to put CODE between dispatching an action and reaching the reducer.
  • 14. Basic redux life-cycle React Action Creator Action Reducers State Calls Returns Sent to Creates new Sent to
  • 15. Redux life-cycle with middlewares Middleware React Action Creator Action Reducers State Calls Returns Sent to Forwards action to Creates new Sent to Middleware receives the action and can log stop and modify it
  • 17. Middleware stack example 1 Middleware # 1 I don’t care about this action, I’ll send it to the NEXT middleware Action Creator Action Reducers next Middleware # 2 I will log this action, and move it forward Middleware # 3 I don’t care about this action, I’ll send it to the NEXT middleware next console.log()
  • 18. Middleware structure ● It is a function that receives the store ● It MUST return a function with arg “next” ● That returns a function with arg “action” ○ Where we do our stuff ○ And return ■ next(action) ■ state.dispatch(action)
  • 19. export default function(store){ return function(next){ return function(action){ //do something //use next(action) or //state.dispatch(action) } } } Middleware structure ES 5 middleware declaration
  • 20. export default store => next => action => { //do something //next(action); or state.dispatch(action); } } Middleware structure ES6 export default ({dispatch}) => next => action => { //our stuff } } src/middleware/myMiddleware.js In case we don’t need the store
  • 22. Simplest example - logger Middleware REACT IncreaseCounter() INC_ACTION ReducersSTATE - counter Forwards action to Component counter + - DecreaseCounter() DEC_ACTION Update state counter logger
  • 23. Using our middleware import {createStore, applyMiddleware } from 'redux'; import reducers from './reducers'; import MyMid from './middlewares/my-middleware'; const createStoreWithMiddleware = applyMiddleware(myMid)(createStore); ReactDOM.render( <Provider store={createStoreWithMiddleware(reducers)}> <App /> </Provider> , document.querySelector('.container')); src/index.js
  • 24. Modify action middleware workflow Middleware that modifies specific action Is it the action that I want? Action Creator Action no yes Send action forwards Next middleware Do some stuff Create new action with the results Action Middleware stack next(action) store.dispatch(newAction)
  • 26. Dispatch action example - superstitious counter Middleware REACT IncreaseCounter() INC_ACTION ReducersSTATE - counter Forwards action to Component counter + - DecreaseCounter() DEC_ACTION Update state counter logger superstitious
  • 28. Thanks for your time! Do you have any questions?