SlideShare a Scribd company logo
1 of 25
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

What's hot (20)

React & Redux
React & ReduxReact & Redux
React & Redux
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
React hooks
React hooksReact hooks
React hooks
 
reactJS
reactJSreactJS
reactJS
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
React-JS.pptx
React-JS.pptxReact-JS.pptx
React-JS.pptx
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
react redux.pdf
react redux.pdfreact redux.pdf
react redux.pdf
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
React js
React jsReact js
React js
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Redux Toolkit - Quick Intro - 2022
Redux Toolkit - Quick Intro - 2022Redux Toolkit - Quick Intro - 2022
Redux Toolkit - Quick Intro - 2022
 
React hooks
React hooksReact hooks
React hooks
 
React js
React jsReact js
React js
 

Similar to Redux workshop

an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to ReduxAmin Ashtiani
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooksSamundra khatri
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptxNavneetKumar111924
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Katy Slemon
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
React Context API
React Context APIReact Context API
React Context APINodeXperts
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareVisual Engineering
 
Workshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedVisual Engineering
 
React gsg presentation with ryan jung & elias malik
React   gsg presentation with ryan jung & elias malikReact   gsg presentation with ryan jung & elias malik
React gsg presentation with ryan jung & elias malikLama K Banna
 
Angular state Management-NgRx
Angular state Management-NgRxAngular state Management-NgRx
Angular state Management-NgRxKnoldus Inc.
 

Similar to Redux workshop (20)

Redux
ReduxRedux
Redux
 
Redux
ReduxRedux
Redux
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
Introduction to Redux.pptx
Introduction to Redux.pptxIntroduction to Redux.pptx
Introduction to Redux.pptx
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux Rorkshop
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
Redux Like Us
Redux Like UsRedux Like Us
Redux Like Us
 
Redux in Angular 2+
Redux in Angular 2+Redux in Angular 2+
Redux in Angular 2+
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React Context API
React Context APIReact Context API
React Context API
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Workshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux AdvancedWorkshop 22: ReactJS Redux Advanced
Workshop 22: ReactJS Redux Advanced
 
React Redux AntD and Umi js
React Redux AntD and Umi jsReact Redux AntD and Umi js
React Redux AntD and Umi js
 
React gsg presentation with ryan jung & elias malik
React   gsg presentation with ryan jung & elias malikReact   gsg presentation with ryan jung & elias malik
React gsg presentation with ryan jung & elias malik
 
Let's start with REDUX
Let's start with REDUXLet's start with REDUX
Let's start with REDUX
 
Fluxxor react library
Fluxxor react libraryFluxxor react library
Fluxxor react library
 
Angular state Management-NgRx
Angular state Management-NgRxAngular state Management-NgRx
Angular state Management-NgRx
 

More from Imran Sayed

Docker with WordPress
Docker with WordPressDocker with WordPress
Docker with WordPressImran Sayed
 
Why Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandWhy Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandImran Sayed
 
Custom gutenberg block development in react
Custom gutenberg block development in reactCustom gutenberg block development in react
Custom gutenberg block development in reactImran Sayed
 
Fastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Fastest Way of Creating Gutenberg Blocks - WordCamp RochesterFastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Fastest Way of Creating Gutenberg Blocks - WordCamp RochesterImran Sayed
 
Harness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPressHarness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPressImran Sayed
 
Improving Your Debugging Skills In WordPress
Improving Your Debugging Skills In WordPressImproving Your Debugging Skills In WordPress
Improving Your Debugging Skills In WordPressImran Sayed
 
Build Modern Web Applications with React and WordPress
Build Modern Web Applications with React and WordPressBuild Modern Web Applications with React and WordPress
Build Modern Web Applications with React and WordPressImran Sayed
 
Why progressive apps for WordPress - WordSesh 2020
Why progressive apps for WordPress - WordSesh 2020Why progressive apps for WordPress - WordSesh 2020
Why progressive apps for WordPress - WordSesh 2020Imran Sayed
 
Digging Into Gutenberg
Digging Into GutenbergDigging Into Gutenberg
Digging Into GutenbergImran Sayed
 
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...
Fastest Way Of Creating  Gutenberg Blocks  With Minimal JavaScript Knowledge ...Fastest Way Of Creating  Gutenberg Blocks  With Minimal JavaScript Knowledge ...
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...Imran Sayed
 
Why progressive web apps for word press wc-ahemdabad
Why progressive web apps for word press wc-ahemdabadWhy progressive web apps for word press wc-ahemdabad
Why progressive web apps for word press wc-ahemdabadImran Sayed
 
Build fast word press site in react in 30 mins with frontity
Build fast word press site in react in 30 mins   with frontityBuild fast word press site in react in 30 mins   with frontity
Build fast word press site in react in 30 mins with frontityImran Sayed
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyImran Sayed
 
Why Progressive Apps For WordPress?
Why Progressive Apps For WordPress?Why Progressive Apps For WordPress?
Why Progressive Apps For WordPress?Imran Sayed
 
Creating Gutenberg Blocks With ACF
Creating Gutenberg Blocks With ACFCreating Gutenberg Blocks With ACF
Creating Gutenberg Blocks With ACFImran Sayed
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with ReactImran Sayed
 
SSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressSSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressImran Sayed
 
React with WordPress : Headless CMS
React with WordPress : Headless CMSReact with WordPress : Headless CMS
React with WordPress : Headless CMSImran Sayed
 
React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of reactImran Sayed
 
Introduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedIntroduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedImran Sayed
 

More from Imran Sayed (20)

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

Recently uploaded

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 

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