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

PPTX
Redux training
PPTX
Thinking in react
PDF
Introduction to Redux
PDF
An Introduction to Redux
PPTX
React/Redux
PDF
react redux.pdf
PDF
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
PPTX
React hooks
Redux training
Thinking in react
Introduction to Redux
An Introduction to Redux
React/Redux
react redux.pdf
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
React hooks

What's hot (20)

PPTX
React + Redux Introduction
PDF
Understanding React hooks | Walkingtree Technologies
PPTX
React workshop
PPTX
Introduction to React
PPTX
React JS: A Secret Preview
PPTX
Its time to React.js
PDF
An introduction to React.js
PPTX
Understanding react hooks
PPT
React js
PDF
Redux Toolkit - Quick Intro - 2022
PDF
React and redux
PDF
Understanding react hooks
PPTX
Reactjs
PPTX
Introduction to React JS for beginners
PPTX
React hooks
PPTX
React workshop presentation
PDF
ReactJS presentation
PPTX
ReactJS presentation.pptx
PDF
React Context API
React + Redux Introduction
Understanding React hooks | Walkingtree Technologies
React workshop
Introduction to React
React JS: A Secret Preview
Its time to React.js
An introduction to React.js
Understanding react hooks
React js
Redux Toolkit - Quick Intro - 2022
React and redux
Understanding react hooks
Reactjs
Introduction to React JS for beginners
React hooks
React workshop presentation
ReactJS presentation
ReactJS presentation.pptx
React Context API
Ad

Similar to Redux workshop (20)

PPTX
an Introduction to Redux
PPTX
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
PDF
React Redux Interview Questions PDF By ScholarHat
PDF
React Redux Interview Questions PDF By ScholarHat
PDF
Materi Modern React Redux Power Point.pdf
PDF
Redux js
PPTX
PPTX
006. React - Redux framework
PPTX
PDF
Redux Deep Dive - ReactFoo Pune 2018
PDF
ReactRedux.pdf
PPTX
Redux Tech Talk
PDF
How to Redux
PDF
Redux State Management System A Comprehensive Review
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
Redux essentials
PDF
Getting started with React and Redux
PPTX
downloads_introduction to redux.pptx
PDF
Let's discover React and Redux with TypeScript
PDF
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
an Introduction to Redux
U3-02-React Redux and MUI.pptxaSDFGNXDASDFG
React Redux Interview Questions PDF By ScholarHat
React Redux Interview Questions PDF By ScholarHat
Materi Modern React Redux Power Point.pdf
Redux js
006. React - Redux framework
Redux Deep Dive - ReactFoo Pune 2018
ReactRedux.pdf
Redux Tech Talk
How to Redux
Redux State Management System A Comprehensive Review
Academy PRO: React JS. Redux & Tooling
Redux essentials
Getting started with React and Redux
downloads_introduction to redux.pptx
Let's discover React and Redux with TypeScript
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
Ad

More from Imran Sayed (20)

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

Recently uploaded (20)

PDF
Odoo Construction Management System by CandidRoot
PDF
What Makes a Great Data Visualization Consulting Service.pdf
PPTX
FLIGHT TICKET API | API INTEGRATION PLATFORM
PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PDF
Module 1 - Introduction to Generative AI.pdf
PDF
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
PPTX
Relevance Tuning with Genetic Algorithms
PPTX
Lesson-3-Operation-System-Support.pptx-I
PDF
solman-7.0-ehp1-sp21-incident-management
PPTX
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PPT
3.Software Design for software engineering
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
PDF
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
PDF
How to Set Realistic Project Milestones and Deadlines
PPTX
Chapter_05_System Modeling for software engineering
PPTX
SAP Business AI_L1 Overview_EXTERNAL.pptx
Odoo Construction Management System by CandidRoot
What Makes a Great Data Visualization Consulting Service.pdf
FLIGHT TICKET API | API INTEGRATION PLATFORM
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
Module 1 - Introduction to Generative AI.pdf
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Relevance Tuning with Genetic Algorithms
Lesson-3-Operation-System-Support.pptx-I
solman-7.0-ehp1-sp21-incident-management
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
3.Software Design for software engineering
Comprehensive Guide to Digital Image Processing Concepts and Applications
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
How to Set Realistic Project Milestones and Deadlines
Chapter_05_System Modeling for software engineering
SAP Business AI_L1 Overview_EXTERNAL.pptx

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