SlideShare a Scribd company logo
ReduxJS
Kavit Shah
Topics
What is redux ?
Redux Principles
Data Flow in Redux
Understanding Action, Reducers, Store
Data flow in React-Redux App
Demo
Redux Utilities
React philosophy
UI is most predictable when it’s the pure function of state. React solves this problem.
Redux is the data/state management library.
Redux attempts to make state mutations predictable by imposing certain restrictions on how and when state updates can
happen.
UI = f (state)
What is Redux?
What is redux?
On the Front end you have to manage states mutations happening either synchronously or asynchronously.
States management includes managing
Server side data
Locally created data which is not persisted on the server
Cached data
the active route, the selected tab, whether to show a spinner or not, should pagination controls be displayed etc…
Mixing state mutations and asynchronicity is like mixing mentos and coke.
Redux Principles
1. Single source of truth - The state of your whole application is stored in an object tree within a single
STORE.
1. State is read-only - The only way to mutate the state is to dispatch an action, an object describing what
happened called ACTION.
1. Changes are made with pure functions - To specify how the state tree is transformed by actions, you
write pure REDUCER.
Data Flow In Redux
State Tree For Simple Todo List
{
visibilityFilter: 'SHOW_ALL',
todos: [
{
id: 1,
text: 'Lets make G2M Awesome',
completed: false
},
...
]
}
Mapping between state tree and reducers
Data Flow In Redux
Actions
Actions is information that send data from your application to your store.
They are the only source of information for the store.
You send them to the store using store.dispatch().
Actions must have a type property that indicates the type of action being performed.
Flux-standard-action is one approach on how to construct your actions.
For example,
{
type: 'TOGGLE_TODO',
index: 5
}
{
type: 'ADD_TODO',
text: 'Complete Code Review'
}
{
type: 'SET_VISIBILITY_FILTER',
filter: 'SHOW_COMPLETED'
}
Action Creator
dispatch(addTodo(text))
Synchronous Action Creator Asynchronous Action Creator
function addTodo(text) {
return {
type: ADD_TODO,
text
}
}
function addTodo(text) {
return ajax.postJSON({
type: ADD_TODO,
text
});
}
Data Flow In Redux
Reducers
Reducers specify how the application’s state changes in response to dispatched action.
Reducer is a function which has the following signature :
(previousState, action) => newState
Reducer Example
function todoApp(state = initialState, action) {
switch (action.type) {
case SET_VISIBILITY_FILTER:
return {
...state,
visibilityFilter: action.filter
}
case ADD_TODO:
return {
state, {
todos: [
...state.todos,
{
text: action.text,
completed: false
}
]
})
default:
return state
}
}
Things not to do inside reducers.
● Mutate the state.
● Perform side effects like API calls and routing
transitions;
● Call impure functions, e.g. Date.now() or
Math.random().
Note:
We always return the previous state for default case.
Data Flow In Redux
Store
The Store is the object that actions and reducers together. The store has the following responsibilities:
Holds application state;
Allows access to state via getState();
Allows state to be updated via dispatch(action);
Registers listeners via subscribe(listener);
Handles unregistering of listeners via the function returned by subscribe(listener).
Redux store implementation
Store
Store
Reducer
{
…
contacts: {}
}
Data Flow In Redux
Data Flow in React-Redux
Presentational component
( Render using updated state )
Container component
store.dispatch(action())
Reducers
(currentState, action) => nextState
State tree
Event handler
Event emitter
Demo
Simple redux counter without UI
Simple react-redux counter with UI
Demo II
Simple redux todo app without UI
Simple react-redux todo app with UI version 1
Simple react-redux todo app with UI, with separate presentational and container
components
Utilities
Name of utility Name of the function Use case of the function
redux-actions ● createAction To create action object with given type and the
payload
react-redux ● Provider
● Connect
Provider - passes store via context
Connect - generates container components
from presentational components
redux-create-reducer ● createReducer Creats a mapping between reducer and event
type. Hence, you don’t have to manage the
mapping
redux ● combineReducers Generates a root reducer from the given set of
reducers
Learning resources
● ReduxJS
● [video] Getting started with redux
● [video] React with redux

More Related Content

PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
Ngrx: Redux in angular
Saadnoor Salehin
 
PDF
Ngrx slides
Christoffer Noring
 
PDF
Getting Started with NgRx (Redux) Angular
Gustavo Costa
 
PDF
React and redux
Mystic Coders, LLC
 
PDF
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
PDF
Introduction to Redux
Ignacio Martín
 
PPTX
React js programming concept
Tariqul islam
 
React + Redux Introduction
Nikolaus Graf
 
Ngrx: Redux in angular
Saadnoor Salehin
 
Ngrx slides
Christoffer Noring
 
Getting Started with NgRx (Redux) Angular
Gustavo Costa
 
React and redux
Mystic Coders, LLC
 
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
Introduction to Redux
Ignacio Martín
 
React js programming concept
Tariqul islam
 

What's hot (20)

PPTX
React state
Ducat
 
PPTX
React hooks
Sadhna Rana
 
PPTX
React js for beginners
Alessandro Valenti
 
PPTX
Redux workshop
Imran Sayed
 
PDF
introduction to Vue.js 3
ArezooKmn
 
PDF
An introduction to React.js
Emanuele DelBono
 
PDF
React JS - Introduction
Sergey Romaneko
 
PPTX
React hooks
Assaf Gannon
 
PPT
Advanced Javascript
Adieu
 
PDF
Java 8-streams-collectors-patterns
José Paumard
 
PPTX
Introduction to React JS for beginners | Namespace IT
namespaceit
 
PDF
React Context API
NodeXperts
 
PDF
Expressjs
Yauheni Nikanovich
 
PDF
50 nouvelles choses que l'on peut faire avec Java 8
José Paumard
 
PPTX
React JS: A Secret Preview
valuebound
 
PDF
Important React Hooks
Knoldus Inc.
 
PPTX
reactJS
Syam Santhosh
 
PDF
VueJS: The Simple Revolution
Rafael Casuso Romate
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
React state
Ducat
 
React hooks
Sadhna Rana
 
React js for beginners
Alessandro Valenti
 
Redux workshop
Imran Sayed
 
introduction to Vue.js 3
ArezooKmn
 
An introduction to React.js
Emanuele DelBono
 
React JS - Introduction
Sergey Romaneko
 
React hooks
Assaf Gannon
 
Advanced Javascript
Adieu
 
Java 8-streams-collectors-patterns
José Paumard
 
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React Context API
NodeXperts
 
50 nouvelles choses que l'on peut faire avec Java 8
José Paumard
 
React JS: A Secret Preview
valuebound
 
Important React Hooks
Knoldus Inc.
 
reactJS
Syam Santhosh
 
VueJS: The Simple Revolution
Rafael Casuso Romate
 
Its time to React.js
Ritesh Mehrotra
 
Ad

Similar to Getting started with Redux js (20)

PDF
React state managmenet with Redux
Vedran Blaženka
 
PDF
Reactивная тяга
Vitebsk Miniq
 
PDF
Materi Modern React Redux Power Point.pdf
exiabreak
 
PPTX
Redux
Maulik Shah
 
PPTX
Redux training
dasersoft
 
PPTX
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
PPTX
Reducers+flux=redux
Shmulik Chicvashvili
 
PPTX
Damian Kmiecik - Road trip with Redux
PROIDEA
 
PDF
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
How to use redux with react hooks in react native application
Katy Slemon
 
PPTX
an Introduction to Redux
Amin Ashtiani
 
PPTX
downloads_introduction to redux.pptx
NavneetKumar111924
 
PDF
[@NaukriEngineering] Flux Architecture
Naukri.com
 
PPTX
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
PPTX
Introduction to react and redux
Cuong Ho
 
PDF
Workshop 20: ReactJS Part II Flux Pattern & Redux
Visual Engineering
 
PPTX
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
PPTX
React + Redux + TypeScript === ♥
Remo Jansen
 
PDF
React
Amitai Barnea
 
React state managmenet with Redux
Vedran Blaženka
 
Reactивная тяга
Vitebsk Miniq
 
Materi Modern React Redux Power Point.pdf
exiabreak
 
Redux training
dasersoft
 
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
Reducers+flux=redux
Shmulik Chicvashvili
 
Damian Kmiecik - Road trip with Redux
PROIDEA
 
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
How to use redux with react hooks in react native application
Katy Slemon
 
an Introduction to Redux
Amin Ashtiani
 
downloads_introduction to redux.pptx
NavneetKumar111924
 
[@NaukriEngineering] Flux Architecture
Naukri.com
 
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Introduction to react and redux
Cuong Ho
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Visual Engineering
 
STATE MANAGEMENT IN REACT [Autosaved].pptx
siddheshjadhav919123
 
React + Redux + TypeScript === ♥
Remo Jansen
 
Ad

Recently uploaded (20)

PPTX
Role Of Python In Programing Language.pptx
jaykoshti048
 
PPTX
TestNG for Java Testing and Automation testing
ssuser0213cb
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PDF
Become an Agentblazer Champion Challenge
Dele Amefo
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Role Of Python In Programing Language.pptx
jaykoshti048
 
TestNG for Java Testing and Automation testing
ssuser0213cb
 
Exploring AI Agents in Process Industries
amoreira6
 
Presentation about variables and constant.pptx
safalsingh810
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
Become an Agentblazer Champion Challenge
Dele Amefo
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
oapresentation.pptx
mehatdhavalrajubhai
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 

Getting started with Redux js

  • 2. Topics What is redux ? Redux Principles Data Flow in Redux Understanding Action, Reducers, Store Data flow in React-Redux App Demo Redux Utilities
  • 3. React philosophy UI is most predictable when it’s the pure function of state. React solves this problem. Redux is the data/state management library. Redux attempts to make state mutations predictable by imposing certain restrictions on how and when state updates can happen. UI = f (state) What is Redux?
  • 4. What is redux? On the Front end you have to manage states mutations happening either synchronously or asynchronously. States management includes managing Server side data Locally created data which is not persisted on the server Cached data the active route, the selected tab, whether to show a spinner or not, should pagination controls be displayed etc…
  • 5. Mixing state mutations and asynchronicity is like mixing mentos and coke.
  • 6. Redux Principles 1. Single source of truth - The state of your whole application is stored in an object tree within a single STORE. 1. State is read-only - The only way to mutate the state is to dispatch an action, an object describing what happened called ACTION. 1. Changes are made with pure functions - To specify how the state tree is transformed by actions, you write pure REDUCER.
  • 7. Data Flow In Redux
  • 8. State Tree For Simple Todo List { visibilityFilter: 'SHOW_ALL', todos: [ { id: 1, text: 'Lets make G2M Awesome', completed: false }, ... ] } Mapping between state tree and reducers
  • 9. Data Flow In Redux
  • 10. Actions Actions is information that send data from your application to your store. They are the only source of information for the store. You send them to the store using store.dispatch(). Actions must have a type property that indicates the type of action being performed. Flux-standard-action is one approach on how to construct your actions. For example, { type: 'TOGGLE_TODO', index: 5 } { type: 'ADD_TODO', text: 'Complete Code Review' } { type: 'SET_VISIBILITY_FILTER', filter: 'SHOW_COMPLETED' }
  • 11. Action Creator dispatch(addTodo(text)) Synchronous Action Creator Asynchronous Action Creator function addTodo(text) { return { type: ADD_TODO, text } } function addTodo(text) { return ajax.postJSON({ type: ADD_TODO, text }); }
  • 12. Data Flow In Redux
  • 13. Reducers Reducers specify how the application’s state changes in response to dispatched action. Reducer is a function which has the following signature : (previousState, action) => newState
  • 14. Reducer Example function todoApp(state = initialState, action) { switch (action.type) { case SET_VISIBILITY_FILTER: return { ...state, visibilityFilter: action.filter } case ADD_TODO: return { state, { todos: [ ...state.todos, { text: action.text, completed: false } ] }) default: return state } } Things not to do inside reducers. ● Mutate the state. ● Perform side effects like API calls and routing transitions; ● Call impure functions, e.g. Date.now() or Math.random(). Note: We always return the previous state for default case.
  • 15. Data Flow In Redux
  • 16. Store The Store is the object that actions and reducers together. The store has the following responsibilities: Holds application state; Allows access to state via getState(); Allows state to be updated via dispatch(action); Registers listeners via subscribe(listener); Handles unregistering of listeners via the function returned by subscribe(listener). Redux store implementation
  • 18. Data Flow In Redux
  • 19. Data Flow in React-Redux Presentational component ( Render using updated state ) Container component store.dispatch(action()) Reducers (currentState, action) => nextState State tree Event handler Event emitter
  • 20. Demo Simple redux counter without UI Simple react-redux counter with UI
  • 21. Demo II Simple redux todo app without UI Simple react-redux todo app with UI version 1 Simple react-redux todo app with UI, with separate presentational and container components
  • 22. Utilities Name of utility Name of the function Use case of the function redux-actions ● createAction To create action object with given type and the payload react-redux ● Provider ● Connect Provider - passes store via context Connect - generates container components from presentational components redux-create-reducer ● createReducer Creats a mapping between reducer and event type. Hence, you don’t have to manage the mapping redux ● combineReducers Generates a root reducer from the given set of reducers
  • 23. Learning resources ● ReduxJS ● [video] Getting started with redux ● [video] React with redux

Editor's Notes

  • #7: Changes in the state is explicit. Hence, it’s possible to keep track of all of them. You can see the history of the state changes and that allows you to do time travel debugging. This approach scales well for medium and complex app. The UI does not need to know how to update the state. All they need to know is which action to dispatch. State mutations happen only using the pure reducers. Pure meaning it can not modify the arguments which are passed to it. It does not do any network calls. If you call the function with the same arguments it always returns the same value. Simple example of impure function is Math.random() or Date().
  • #8: One way data flow between different components.