SlideShare a Scribd company logo
1 of 14
Redux Like Us
August 2018
Heber Silva
Redux
What’s Redux?
Is a predictable state management container library for JavaScript
apps. Itself is a small library of 2KB. It was release in June 2, 2015
by Dan Abramov.
What is a state?
Is a data that React component holds to render to the
user.
Before understand what is Redux need
to understand what’s a state…
Redux keep tracks of small things (states) in JavaScript
3
What does the Redux solve?
Even a silly to-do list could become
unmanageable if you starting passing the state
up and down.
Examples of state
• Data the user sees
• Data we fetch
• URL we are showing to the user
• Selected items inside the page
• Errors messages in the applications
Unmanageable states…
Things will become tricky…
5
“Without
Redux your
React app
passes state
up and down
the tree
nodes…”
“With Redux
your React app
dispatches
updates to
states to a
single tree
node…”
When to use Redux?
• Multiple React components needs to access the same state but do not
have any parent/child relationship
• You start to feel awkward passing down the state to multiple
components with props
How all parts go together?
7
Store
Orchestrates all the moving pats in Redux. The state of the whole lives inside the store.
Reducer
A JavaScript function that takes two arguments, current state and an action. The state must
return entirely from reducers. Then data state are never mutated, that only copied.
Action
Sends out signal to the store to change the state called dispatching an action.
Container
When you connect your component to Redux, you connect with two arguments based use cases.
• mapStateToProps – Connect parts of the Redux state to the props of a React Component.
So, your component can have exact part of the store it needs.
• mapDispatchToProps – Connects Redux actions to React props. This way your component
will be able to dispatch actions.
Store
8
// src/js/store/index.js
import { createStore } from "redux";
import rootReducer from "../reducers/index";
const store = createStore(rootReducer);
export default store;
Store methods
• getState for accessing the current state of the application
• dispatch for dispatching an action
• subscribe for listening on state changes
Code:
9
Reducer
import { ADD_BANANA } from "../constants/action-types";
const initialState = {
banana: []
};
const rootReducer = (state = initialState, action) => {
switch (action.type) {
case ADD_BANANA:
return { ...state , banana: action.banana };
default:
return state;
}
};
export default rootReducer;
Code:
10
Action
// src/js/actions/index.js
import { ADD_BANANA } from "../constants/action-types";
export const addBanana = banana => ({ type: ADD_BANANA,
payload: banana });
Code:
11
Container
Code:
const mapStateToProps = state => {
return { ingredient: state.ingredient };
};
const mapDispatchToProps = dispatch => {
return {
addIncredient: ingredient => dispatch(addIngredient(ingredient))
};
};
export default connect(mapStateToProps, mapDispatchToProps)(Component)
import { connect } from "react-redux";
Redux Flow
12
Live Human Component
13
<LiveHumanComponent />
Live Code
14
<LiveCode />

More Related Content

What's hot

Aspnet Life Cycles Events
Aspnet Life Cycles EventsAspnet Life Cycles Events
Aspnet Life Cycles Events
LiquidHub
 

What's hot (20)

an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
Spfx with react redux
Spfx with react reduxSpfx with react redux
Spfx with react redux
 
Aspnet Life Cycles Events
Aspnet Life Cycles EventsAspnet Life Cycles Events
Aspnet Life Cycles Events
 
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
React Redux Tutorial | Redux Tutorial for Beginners | React Redux Training | ...
 
Introduction to React Hooks
Introduction to React HooksIntroduction to React Hooks
Introduction to React Hooks
 
Aws schema conversion tool
Aws schema conversion toolAws schema conversion tool
Aws schema conversion tool
 
React & ES6 Intro
React & ES6 IntroReact & ES6 Intro
React & ES6 Intro
 
Meetup dpjs react_api
Meetup dpjs react_apiMeetup dpjs react_api
Meetup dpjs react_api
 
React: High level overview for backend developers
React: High level overview for backend developersReact: High level overview for backend developers
React: High level overview for backend developers
 
GITS Class #20: Building A Fast and Responsive UI in React Native
GITS Class #20: Building A Fast and Responsive UI in React NativeGITS Class #20: Building A Fast and Responsive UI in React Native
GITS Class #20: Building A Fast and Responsive UI in React Native
 
React App State Management with react hooks and context api
React App State Management with react hooks and context apiReact App State Management with react hooks and context api
React App State Management with react hooks and context api
 
reactJS
reactJSreactJS
reactJS
 
React context
React context  React context
React context
 
GITS Class #19: Build Large Scale Vue.js Apps with Vuex
GITS Class #19: Build Large Scale Vue.js Apps with VuexGITS Class #19: Build Large Scale Vue.js Apps with Vuex
GITS Class #19: Build Large Scale Vue.js Apps with Vuex
 
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...
 
Basic Fundamental of Redux
Basic Fundamental of ReduxBasic Fundamental of Redux
Basic Fundamental of Redux
 
Robust UI development with ClojureScript
Robust UI development with ClojureScriptRobust UI development with ClojureScript
Robust UI development with ClojureScript
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
Event streams all the way down
Event streams all the way downEvent streams all the way down
Event streams all the way down
 
Corespring
CorespringCorespring
Corespring
 

Similar to Redux Like Us

ReactRedux.pdf
ReactRedux.pdfReactRedux.pdf
ReactRedux.pdf
Arsalan malik
 

Similar to Redux Like Us (20)

React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
React.js+Redux Workshops
React.js+Redux WorkshopsReact.js+Redux Workshops
React.js+Redux Workshops
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
Redux
ReduxRedux
Redux
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Reactjs
Reactjs Reactjs
Reactjs
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
 
React presentation-google-hackathon
React presentation-google-hackathonReact presentation-google-hackathon
React presentation-google-hackathon
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
A React Journey
A React JourneyA React Journey
A React Journey
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
 
FRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptxFRONTEND BOOTCAMP 4.pptx
FRONTEND BOOTCAMP 4.pptx
 
React introduction
React introductionReact introduction
React introduction
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
ReactJs
ReactJsReactJs
ReactJs
 
Redux State Management System A Comprehensive Review
Redux State Management System A Comprehensive ReviewRedux State Management System A Comprehensive Review
Redux State Management System A Comprehensive Review
 
ReactRedux.pdf
ReactRedux.pdfReactRedux.pdf
ReactRedux.pdf
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
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
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
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
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 

Redux Like Us

  • 1. Redux Like Us August 2018 Heber Silva
  • 2. Redux What’s Redux? Is a predictable state management container library for JavaScript apps. Itself is a small library of 2KB. It was release in June 2, 2015 by Dan Abramov. What is a state? Is a data that React component holds to render to the user. Before understand what is Redux need to understand what’s a state…
  • 3. Redux keep tracks of small things (states) in JavaScript 3
  • 4. What does the Redux solve? Even a silly to-do list could become unmanageable if you starting passing the state up and down. Examples of state • Data the user sees • Data we fetch • URL we are showing to the user • Selected items inside the page • Errors messages in the applications Unmanageable states…
  • 5. Things will become tricky… 5 “Without Redux your React app passes state up and down the tree nodes…” “With Redux your React app dispatches updates to states to a single tree node…”
  • 6. When to use Redux? • Multiple React components needs to access the same state but do not have any parent/child relationship • You start to feel awkward passing down the state to multiple components with props
  • 7. How all parts go together? 7 Store Orchestrates all the moving pats in Redux. The state of the whole lives inside the store. Reducer A JavaScript function that takes two arguments, current state and an action. The state must return entirely from reducers. Then data state are never mutated, that only copied. Action Sends out signal to the store to change the state called dispatching an action. Container When you connect your component to Redux, you connect with two arguments based use cases. • mapStateToProps – Connect parts of the Redux state to the props of a React Component. So, your component can have exact part of the store it needs. • mapDispatchToProps – Connects Redux actions to React props. This way your component will be able to dispatch actions.
  • 8. Store 8 // src/js/store/index.js import { createStore } from "redux"; import rootReducer from "../reducers/index"; const store = createStore(rootReducer); export default store; Store methods • getState for accessing the current state of the application • dispatch for dispatching an action • subscribe for listening on state changes Code:
  • 9. 9 Reducer import { ADD_BANANA } from "../constants/action-types"; const initialState = { banana: [] }; const rootReducer = (state = initialState, action) => { switch (action.type) { case ADD_BANANA: return { ...state , banana: action.banana }; default: return state; } }; export default rootReducer; Code:
  • 10. 10 Action // src/js/actions/index.js import { ADD_BANANA } from "../constants/action-types"; export const addBanana = banana => ({ type: ADD_BANANA, payload: banana }); Code:
  • 11. 11 Container Code: const mapStateToProps = state => { return { ingredient: state.ingredient }; }; const mapDispatchToProps = dispatch => { return { addIncredient: ingredient => dispatch(addIngredient(ingredient)) }; }; export default connect(mapStateToProps, mapDispatchToProps)(Component) import { connect } from "react-redux";