SlideShare a Scribd company logo
1
Redux
IVAN LOVRIĆ
2
Redux
Open-source JavaScript library
Designed for managing application state
3
Redux
Simple
No setup
Complex
Significant setup
JS jQuery React React + Redux
Complex data flows
Inter-component communication
Non-hierarchical data
Many actions
Same data used in multiple places
WHEN DO I NEED REDUX?
4
Redux
ACTIONS
REDUCERS
STORE
PURE FUNCTIONS
IMMUTABILITY
WHAT ARE WE GOING TO LEARN:
REDUX
…AND MORE
5
Redux
One immutable store Actions trigger changes Reducers update state
3 PRINCIPLES OF REDUX
6
Redux
REDUX FLOW
Action
Store
React
Reducers
function appReducer(state, action) {
switch(action.type){
case RATE_COURSE:
// return new state
}
}
{ type: RATE_COURSE, rating: 5 }
Notified via React-Redux
7
Redux
REDUX ACTION
rateCourse(rating){
return { type: RATE_COURSE, rating: rating }
}
{ type: RATE_COURSE, rating: rating }
REDUX ACTION CREATOR
USING ACTION CONSTANTS
export const RATE_COURSE = 'RATE_COURSE';
8
Redux
function myReducer(state, action){
switch (action.type){
case INCREMENT_COUNTER:
// return new state based on action passed
}
}
REDUX REDUCER
“state is read-only”
9
Redux
REDUX REDUCER
“changes are made with pure functions”
// Pure functions
function square(x) {
return x * x;
}
function squareAll(items) {
return items.map(square);
}
10
Redux
REDUX REDUCER
“changes are made with pure functions”
// Impure functions
function square(x) {
updateXInDatabase(x);
return x * x;
}
function squareAll(items) {
for (let i = 0; i < items.length; i++) {
items[i] = square(items[i]);
}
}
11
Redux
FORBIDDEN IN REDUCERS
Mutate arguments
Perform side effects
Call non-pure functions
12
Redux
ALL REDUCERS ARE CALLED ON EACH DISPATCH
loadStatus
courses
authors
{ type: DELETE_COURSE, 1 }
New State
13
Redux
REDUX REDUCER
“slice of state”
Red
ucer
Red
ucer
Red
ucer
State
Store
14
Redux
store.dispatch(action)
store.subscribe(listener)
store.getState()
replaceReducer(nextReducer)
const store = createStore(reducer);
REDUX STORE
“single source of truth”
15
Redux
IMMUTABILITY
“to change state, return a new object”
state = {
name: ‘Ivan’,
role: ‘developer’
}
state.role = ‘admin’;
return state;
state = {
name: ‘Ivan’,
role: ‘developer’
}
return state = {
name: ‘Ivan’,
role: ‘admin’
}
MUTATING STATE NOT MUTATING STATE
16
Redux
IMMUTABILITY
“to change state, return a new object”
Object.assign(target, ...sources)
Object.assign({}, state, { role: ‘admin’ });
SIGNATURE
EXAMPLE
Handling Immutable State
Object.assign
Spread operator
Lodash merge
Lodash extend
Object-assign
react-addons-update
Immutable.js
ES6 ES5 LIBRARIES
17
Redux
Clarity
Performanse
Awesome sauce
WHY IMMUTABILITY?
Q: “Huh, who changed that state?”
A: “The reducer, stupid!”
Q: “Has this changed?”
18
Redux
SUMMARY: DATA FLOW
Store UI
Redux Action
State
defines
triggers
sent to
updates
contains
19
DEMO
https://bitbucket.org/IvanLovric/fesb-react-redux
20
Redux
ACTIONS
Represent user intent
Must have a type
STORE
dispatch, subscribe, getState…
IMMUTABILITY
Just return a new copy
REDUCERS
Must be pure
Multiple per app
Slice of state
21
CAREERS
22
Q&A

More Related Content

PPTX
Getting started with Redux js
PDF
ReactRedux.pdf
PPTX
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
PDF
React.js and Redux overview
PPTX
Introduction to Redux.pptx
PPTX
downloads_introduction to redux.pptx
PDF
Evan Schultz - Angular Summit - 2016
PPTX
an Introduction to Redux
Getting started with Redux js
ReactRedux.pdf
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
React.js and Redux overview
Introduction to Redux.pptx
downloads_introduction to redux.pptx
Evan Schultz - Angular Summit - 2016
an Introduction to Redux

Similar to The Redux Introduction in react and applications . (20)

PDF
Redux essentials
PPTX
Redux Tech Talk
PDF
Angular2 and Redux - up & running - Nir Kaufman - Codemotion Amsterdam 2016
PPTX
Redux training
PDF
Getting started with React and Redux
PDF
Redux tutorial - intro to Redux by GetLittleTech
PDF
An Introduction to Redux
PDF
Redux js
PDF
Understanding redux
PDF
Introduction to Redux (for Angular and React devs)
PDF
React Redux Interview Questions PDF By ScholarHat
PDF
React Redux Interview Questions PDF By ScholarHat
PDF
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
PDF
How to Redux
PPTX
Redux Like Us
PPTX
Redux workshop
PPTX
006. React - Redux framework
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
Redux State Management System A Comprehensive Review
PDF
Redux in Angular 2+
Redux essentials
Redux Tech Talk
Angular2 and Redux - up & running - Nir Kaufman - Codemotion Amsterdam 2016
Redux training
Getting started with React and Redux
Redux tutorial - intro to Redux by GetLittleTech
An Introduction to Redux
Redux js
Understanding redux
Introduction to Redux (for Angular and React devs)
React Redux Interview Questions PDF By ScholarHat
React Redux Interview Questions PDF By ScholarHat
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
How to Redux
Redux Like Us
Redux workshop
006. React - Redux framework
Academy PRO: React JS. Redux & Tooling
Redux State Management System A Comprehensive Review
Redux in Angular 2+
Ad

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
composite construction of structures.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
web development for engineering and engineering
PPTX
OOP with Java - Java Introduction (Basics)
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPT
Project quality management in manufacturing
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
composite construction of structures.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Mechanical Engineering MATERIALS Selection
Operating System & Kernel Study Guide-1 - converted.pdf
web development for engineering and engineering
OOP with Java - Java Introduction (Basics)
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
additive manufacturing of ss316l using mig welding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Project quality management in manufacturing
Ad

The Redux Introduction in react and applications .