SlideShare a Scribd company logo
Introduction to
Redux
Redux
2
● Redux is a state management tool for javascript apps.
● Allows you to share the state between components
Redux
3
Store
Reducers
Actions
State
● It integrates nicely
with React. Can use it
with any other view
library. It allow us to
track changing data.
● It’s pretty similar to
component state
Why use redux?
● When we have big complicated data for complex
applications.
● Any component can pull any piece of data from the redux
store.So data needs to be shared between multiple
components
● Helps you write applications that behave consistently.
● Run in different environments (client, server, and native),
and are easy to test
● Provides a great developer experience, such as live code
editing combined with a time traveling debugger.
● Reusing the components because they no longer are
dependent to get the props from their parents, they can all
get their state values as props ,from a single redux store
4
Actions Reducers Store State
5
Triggers an action Create & Dispatch an Action
Updates store with
new state based on
action type
Defines
Actions & Action Creators
● Actions are kind of events. And they are just objects.
● Actions look like this:
● Instead of writing them ourselves we can wrap them inside
a function that returns this action object. And this function is
called Action Creators.
So action creators create
actions.
6
Action Creators
● Action creators (functions that return action object ) make
your job easier when you need to dispatch the same action
at multiple places
● One action can trigger multiple side-effects, depending on
how many reducers consume that action, by checking
action.type and returning a new state
● In the below example action creators dispatches a
synchronous action. If you want to dispatch asynchronous
actions, you need to use redux thunk
7
Middlewares
● A middleware is some code you can put between the
framework receiving a request, and the framework
generating a response
● People use Redux middleware for logging, crash reporting,
talking to an asynchronous API, routing, and more.
Examples redux-thunk, redux-logger etc.
8
Redux Thunk
● Redux thunk is a middleware, that looks at every action that
passes through the system and if its a function it calls that
function.
9
Redux Thunk
● With a plain basic Redux store, you can only do simple
synchronous updates by dispatching an action.
● Middleware extend the store's abilities, and let you write
async logic that interacts with the store.
● So with redux-thunk you can handle asynchronous
actions, rather than synchronous actions.
10
Synchronous Actions
11
Asynchronous Actions( with thunk )
12
Redux Logger
● Display prevState,nextState
and action in the
console Log, everytime
an action is fired.
● npm i -D redux-logger
13
Reducers
● Reducers take an initial State, create a new state based on
the action.type and the update the redux store with the
new state.
● It must return a new state
14
Redux Store
● Store provides a universal data storage.
● You can create redux store using createStore(). We must
pass reducer as its first parameter. It takes an optional
second parameter as ‘intialState’ and an optional
‘middleware’ which allows us to pass multiple middlewares
like ‘thunk’, ‘redux-logger’ etc.
15
Redux Store
● We can then wrap our main component inside Provider and
pass our redux store into it, so any component can access
redux store.
● Any component
inside Provider
can also dispatch
an action.
16
Connect
● Connect is a higher order component, that can take upto four
parameters. All are optional.
https://react-redux.js.org/api/connect#connect-parameters
connect(mapStateToProps?, mapDispatchToProps?)
● mapStateToProps: is a function that gives you the store values as
props for your component. It takes store’s state as param and
returns an object which gets added as props for your component.
17
Connect
● mapDispatchToProps: can be a function( that returns an
object ) or an object. If this parameter is not passed, then
your component will receive ‘dispatch’ by default.
● Each property of the returned object should be a function,
that dispatches an action
● Passing mapDispatchToProps as a function
● Passing mapDisptachToProps as Object:
Here fetchPosts is a actionCreator ( function ) that we have
imported, that dispatches an action.
18
Connect
● The return of connect() is a wrapper function that takes
your component and returns a wrapper component with
the additional props that it injects.
● However it does not change your component, it just returns
a new component with props injected in it.
● https://react-redux.js.org/api/connect#connect-returns
19
When to use Connect?
● There can be two types of components:
1. Smart Component
2. Dumb Component
● Smart Components are the ones which use connect(), take
the store data as props use them for themselves and then
can pass it to Dumb Components down in the tree.
● You should avoid passing props to multiple level child
Components as it would also make them hard to test.
20
Actions Reducers Store State
21
Triggers an action Dispatch Action ( type & payload )
Updates store with
new state based on
action type
Action: (type & payload)
prevState & Action
Defines
22
Triggers an action Dispatch Action ( type & payload )
Updates store with
new state based on
action type
Action: (type & payload)
prevState & Action
Defines
Steps
23
● Create a reducer and return state based on action type ( optional :
combinereducer )
● Create(return) an action using action creator
● Create a store and pass the reducer ( optional: add middleware )
● Call the action creator using store.dispatch( actionCreator() ) ( If not
react )
Additional steps For React,
● Wrap your component inside Provider and pass store
● Connect your React with redux : connect( mapStateToProps)( Compo )
● Call actionCreator using this.props.dispatch( actionCreator )
Difference between Component
state & Store state
Component State
=A component state can be
changed
=State is managed within a
component and can only be
passed as props with a top to
bottom data flow
- State value can change, and
then render function is called..
Redux Store state
-A redux store state is
immutable.So reducers never
changes the state but create a
new state each time and updates
the store
-Any component can access it
=Reducer updates the store with a
new state when an action is
dispatched.
24
25
Thanks!
Any questions?
@imranhsayed
@imran_.sayed

More Related Content

What's hot (20)

PDF
An Introduction to Redux
NexThoughts Technologies
 
PPTX
Intro to React
Eric Westfall
 
ODP
Introduction to ReactJS
Knoldus Inc.
 
PPTX
React js for beginners
Alessandro Valenti
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPTX
React js programming concept
Tariqul islam
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
PDF
React and redux
Mystic Coders, LLC
 
PPTX
React-JS.pptx
AnmolPandita7
 
PPTX
React JS: A Secret Preview
valuebound
 
PPTX
Introduction to react_js
MicroPyramid .
 
PPTX
React workshop
Imran Sayed
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
React JS - Introduction
Sergey Romaneko
 
PDF
An introduction to React.js
Emanuele DelBono
 
PPTX
React js
Oswald Campesato
 
PPTX
reactJS
Syam Santhosh
 
PPTX
Redux training
dasersoft
 
PDF
React new features and intro to Hooks
Soluto
 
An Introduction to Redux
NexThoughts Technologies
 
Intro to React
Eric Westfall
 
Introduction to ReactJS
Knoldus Inc.
 
React js for beginners
Alessandro Valenti
 
React + Redux Introduction
Nikolaus Graf
 
Introduction to React JS for beginners
Varun Raj
 
React js programming concept
Tariqul islam
 
Its time to React.js
Ritesh Mehrotra
 
React and redux
Mystic Coders, LLC
 
React-JS.pptx
AnmolPandita7
 
React JS: A Secret Preview
valuebound
 
Introduction to react_js
MicroPyramid .
 
React workshop
Imran Sayed
 
ReactJS presentation
Thanh Tuong
 
React JS - Introduction
Sergey Romaneko
 
An introduction to React.js
Emanuele DelBono
 
reactJS
Syam Santhosh
 
Redux training
dasersoft
 
React new features and intro to Hooks
Soluto
 

Similar to Redux workshop (20)

PPTX
an Introduction to Redux
Amin Ashtiani
 
PPTX
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
PDF
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
PDF
Materi Modern React Redux Power Point.pdf
exiabreak
 
PDF
Redux js
Nils Petersohn
 
PPTX
Redux
Maulik Shah
 
PPTX
006. React - Redux framework
Binh Quan Duc
 
PPTX
Redux
Anurag Chitti
 
PDF
Redux Deep Dive - ReactFoo Pune 2018
Aziz Khambati
 
PDF
ReactRedux.pdf
Arsalan malik
 
PPTX
Redux Tech Talk
Chathuranga Jayanath
 
PDF
How to Redux
Ted Pennings
 
PDF
Redux State Management System A Comprehensive Review
ijtsrd
 
PPTX
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
PDF
Redux essentials
Chandan Kumar Rana
 
PDF
Getting started with React and Redux
Paddy Lock
 
PPTX
downloads_introduction to redux.pptx
NavneetKumar111924
 
PDF
Let's discover React and Redux with TypeScript
Mathieu Savy
 
PDF
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
Edureka!
 
an Introduction to Redux
Amin Ashtiani
 
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
vinodkumarthatipamul
 
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
React Redux Interview Questions PDF By ScholarHat
Scholarhat
 
Materi Modern React Redux Power Point.pdf
exiabreak
 
Redux js
Nils Petersohn
 
006. React - Redux framework
Binh Quan Duc
 
Redux Deep Dive - ReactFoo Pune 2018
Aziz Khambati
 
ReactRedux.pdf
Arsalan malik
 
Redux Tech Talk
Chathuranga Jayanath
 
How to Redux
Ted Pennings
 
Redux State Management System A Comprehensive Review
ijtsrd
 
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Redux essentials
Chandan Kumar Rana
 
Getting started with React and Redux
Paddy Lock
 
downloads_introduction to redux.pptx
NavneetKumar111924
 
Let's discover React and Redux with TypeScript
Mathieu Savy
 
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
Edureka!
 
Ad

More from Imran Sayed (20)

PPTX
Docker with WordPress
Imran Sayed
 
PPTX
Why Progressive Web Apps For WordPress - WordCamp Finland
Imran Sayed
 
PPTX
Custom gutenberg block development in react
Imran Sayed
 
PPTX
Fastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Imran Sayed
 
PPTX
Harness The Power Of ACF For Gatsby and WordPress
Imran Sayed
 
PPTX
Improving Your Debugging Skills In WordPress
Imran Sayed
 
PPTX
Build Modern Web Applications with React and WordPress
Imran Sayed
 
PPTX
Why progressive apps for WordPress - WordSesh 2020
Imran Sayed
 
PPTX
Digging Into Gutenberg
Imran Sayed
 
PPTX
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...
Imran Sayed
 
PDF
Why progressive web apps for word press wc-ahemdabad
Imran Sayed
 
PPTX
Build fast word press site in react in 30 mins with frontity
Imran Sayed
 
PPTX
Build Fast WordPress Site With Gatsby
Imran Sayed
 
PPTX
Why Progressive Apps For WordPress?
Imran Sayed
 
PPTX
Creating Gutenberg Blocks With ACF
Imran Sayed
 
PPTX
Custom gutenberg block development with React
Imran Sayed
 
PPTX
SSR with React - Connecting Next.js with WordPress
Imran Sayed
 
PDF
React with WordPress : Headless CMS
Imran Sayed
 
PPTX
React Workshop: Core concepts of react
Imran Sayed
 
PPTX
Introduction to Gutenberg- Imran Sayed
Imran Sayed
 
Docker with WordPress
Imran Sayed
 
Why Progressive Web Apps For WordPress - WordCamp Finland
Imran Sayed
 
Custom gutenberg block development in react
Imran Sayed
 
Fastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Imran Sayed
 
Harness The Power Of ACF For Gatsby and WordPress
Imran Sayed
 
Improving Your Debugging Skills In WordPress
Imran Sayed
 
Build Modern Web Applications with React and WordPress
Imran Sayed
 
Why progressive apps for WordPress - WordSesh 2020
Imran Sayed
 
Digging Into Gutenberg
Imran Sayed
 
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...
Imran Sayed
 
Why progressive web apps for word press wc-ahemdabad
Imran Sayed
 
Build fast word press site in react in 30 mins with frontity
Imran Sayed
 
Build Fast WordPress Site With Gatsby
Imran Sayed
 
Why Progressive Apps For WordPress?
Imran Sayed
 
Creating Gutenberg Blocks With ACF
Imran Sayed
 
Custom gutenberg block development with React
Imran Sayed
 
SSR with React - Connecting Next.js with WordPress
Imran Sayed
 
React with WordPress : Headless CMS
Imran Sayed
 
React Workshop: Core concepts of react
Imran Sayed
 
Introduction to Gutenberg- Imran Sayed
Imran Sayed
 
Ad

Recently uploaded (20)

PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 

Redux workshop

  • 2. Redux 2 ● Redux is a state management tool for javascript apps. ● Allows you to share the state between components
  • 3. Redux 3 Store Reducers Actions State ● It integrates nicely with React. Can use it with any other view library. It allow us to track changing data. ● It’s pretty similar to component state
  • 4. Why use redux? ● When we have big complicated data for complex applications. ● Any component can pull any piece of data from the redux store.So data needs to be shared between multiple components ● Helps you write applications that behave consistently. ● Run in different environments (client, server, and native), and are easy to test ● Provides a great developer experience, such as live code editing combined with a time traveling debugger. ● Reusing the components because they no longer are dependent to get the props from their parents, they can all get their state values as props ,from a single redux store 4
  • 5. Actions Reducers Store State 5 Triggers an action Create & Dispatch an Action Updates store with new state based on action type Defines
  • 6. Actions & Action Creators ● Actions are kind of events. And they are just objects. ● Actions look like this: ● Instead of writing them ourselves we can wrap them inside a function that returns this action object. And this function is called Action Creators. So action creators create actions. 6
  • 7. Action Creators ● Action creators (functions that return action object ) make your job easier when you need to dispatch the same action at multiple places ● One action can trigger multiple side-effects, depending on how many reducers consume that action, by checking action.type and returning a new state ● In the below example action creators dispatches a synchronous action. If you want to dispatch asynchronous actions, you need to use redux thunk 7
  • 8. Middlewares ● A middleware is some code you can put between the framework receiving a request, and the framework generating a response ● People use Redux middleware for logging, crash reporting, talking to an asynchronous API, routing, and more. Examples redux-thunk, redux-logger etc. 8
  • 9. Redux Thunk ● Redux thunk is a middleware, that looks at every action that passes through the system and if its a function it calls that function. 9
  • 10. Redux Thunk ● With a plain basic Redux store, you can only do simple synchronous updates by dispatching an action. ● Middleware extend the store's abilities, and let you write async logic that interacts with the store. ● So with redux-thunk you can handle asynchronous actions, rather than synchronous actions. 10
  • 13. Redux Logger ● Display prevState,nextState and action in the console Log, everytime an action is fired. ● npm i -D redux-logger 13
  • 14. Reducers ● Reducers take an initial State, create a new state based on the action.type and the update the redux store with the new state. ● It must return a new state 14
  • 15. Redux Store ● Store provides a universal data storage. ● You can create redux store using createStore(). We must pass reducer as its first parameter. It takes an optional second parameter as ‘intialState’ and an optional ‘middleware’ which allows us to pass multiple middlewares like ‘thunk’, ‘redux-logger’ etc. 15
  • 16. Redux Store ● We can then wrap our main component inside Provider and pass our redux store into it, so any component can access redux store. ● Any component inside Provider can also dispatch an action. 16
  • 17. Connect ● Connect is a higher order component, that can take upto four parameters. All are optional. https://react-redux.js.org/api/connect#connect-parameters connect(mapStateToProps?, mapDispatchToProps?) ● mapStateToProps: is a function that gives you the store values as props for your component. It takes store’s state as param and returns an object which gets added as props for your component. 17
  • 18. Connect ● mapDispatchToProps: can be a function( that returns an object ) or an object. If this parameter is not passed, then your component will receive ‘dispatch’ by default. ● Each property of the returned object should be a function, that dispatches an action ● Passing mapDispatchToProps as a function ● Passing mapDisptachToProps as Object: Here fetchPosts is a actionCreator ( function ) that we have imported, that dispatches an action. 18
  • 19. Connect ● The return of connect() is a wrapper function that takes your component and returns a wrapper component with the additional props that it injects. ● However it does not change your component, it just returns a new component with props injected in it. ● https://react-redux.js.org/api/connect#connect-returns 19
  • 20. When to use Connect? ● There can be two types of components: 1. Smart Component 2. Dumb Component ● Smart Components are the ones which use connect(), take the store data as props use them for themselves and then can pass it to Dumb Components down in the tree. ● You should avoid passing props to multiple level child Components as it would also make them hard to test. 20
  • 21. Actions Reducers Store State 21 Triggers an action Dispatch Action ( type & payload ) Updates store with new state based on action type Action: (type & payload) prevState & Action Defines
  • 22. 22 Triggers an action Dispatch Action ( type & payload ) Updates store with new state based on action type Action: (type & payload) prevState & Action Defines
  • 23. Steps 23 ● Create a reducer and return state based on action type ( optional : combinereducer ) ● Create(return) an action using action creator ● Create a store and pass the reducer ( optional: add middleware ) ● Call the action creator using store.dispatch( actionCreator() ) ( If not react ) Additional steps For React, ● Wrap your component inside Provider and pass store ● Connect your React with redux : connect( mapStateToProps)( Compo ) ● Call actionCreator using this.props.dispatch( actionCreator )
  • 24. Difference between Component state & Store state Component State =A component state can be changed =State is managed within a component and can only be passed as props with a top to bottom data flow - State value can change, and then render function is called.. Redux Store state -A redux store state is immutable.So reducers never changes the state but create a new state each time and updates the store -Any component can access it =Reducer updates the store with a new state when an action is dispatched. 24