SlideShare a Scribd company logo
Intro to React & Redux
Boris Dinkevich
http://500Tech.com
boris@500tech.com
Boris Dinkevich
- React evangelist
- Past Angular hippie
- CoAuthor of 

The Complete Redux Book
CoFounder @ 500Tech
ES2015 (ES6)
Const & Let
Strings
Arrow functions
Destructuring
A WORD ON TOOLS
npm - package repository
babel - transpiler
webpack - build tool
BACK TO REACT
HISTORY
Component Driven Development
Thinking in components
Thinking in components
Lifecycle methods
Mount
componentWillMount → Angular PreLink
componentDidMount → Angular PostLink
Update
componentWillUpdate
componentDidUpdate
Unmount
componentWillUnmount → $scope.$on('destroy')
Virtual DOM
Recipe
Ingredients
Eggs
Virtual DOM
Recipe
Ingredients
Eggs
Real DOM
=
Recipe
Ingredients
Eggs
Recipe
Ingredients
MilkEggs
New Virtual DOM
Recipe
Ingredients
Eggs
Old Virtual DOM
Real DOM
!=
JSX
https://babeljs.io/repl/
Play with JSX online
=
function App() {

return React.createElement('div', null, [

React.createElement('h1', null, 'I am a component!'),

React.createElement('h2', null, 'I am a sub title')

]);

}


function App() {

return (

<div>

<h1>I am a component!</h1>

<h2>I am a sub title</h2>

</div>

);

}
PROPS
Passing Props
const Add = (props) => (

<h2>Its: { props.a + props.b }</h2>

);



const App = () => (

<Add a={ 2 } b={ 3 } />

);
Repeating with JavaScript
(3/3)
const Recipes = ({ recipes }) => (

<div>

<h1>Recipes</h1>

<ul>

{

recipes.map((recipe) => <Recipe recipe={ recipe } />)

}

</ul>

</div>

);
CLASSES
Make <App /> into a class
class App extends React.Component {

render() {

return (

<div>

<Recipes recipes={ recipes }/>

</div>

);

}

}

Component Lifecycle
class MyComponent extends React.Component {

constructor() { }

render() { }


getInitialState() { }

getDefaultProps() { }

componentWillMount() { }

componentDidMount() { }

componentWillReceiveProps() { }

shouldComponentUpdate() { }

componentWillUpdate() { }

componentDidUpdate() { }

componentWillUnmount() { }

}
https://facebook.github.io/react/docs/component-specs.html
CHANGE DETECTION
Change detection
Props change
State change - setState()
Forced - forceUpdate()
Add a recipe after 1sec
constructor() {

super();



setTimeout(() => {

console.log(`Adding new recipe`);

recipes.push('Shakshuka');

}, 1000);

}
PROP TYPES
Setting PropTypes
AddRecipe.propTypes = {

addRecipe: React.PropTypes.func.isRequired

};
add-recipe.js
https://facebook.github.io/react/docs/reusable-components.html
FLUX
MVC
FLUX
Flux
Components
Dispatcher
ActionsStores
Introduction to React & Redux
Game engine
Store
Recipes
Waffles
App
Add RecipeRecipes
Recipe…Omelette Pancakes Recipe… Recipe…
REDUX
Click
Timeout
AJAX
Websocket
EVERYTHING IS AN ACTION
Add Recipe
Toggle Favorite
Fetch Recipes
Start Network
Current State
Next State
Reducers
(processors)
Action
Many reducers can be chained
Must return a new state — never modify previous one
Object.assign or Immutable
Only one store
REDUCERS
CONNECT
State to React
Store
Recipes
Recipe 1 Recipe 2
App
Recipes Add Recipe
Recipe 1 Recipe 2
State to React
Store
Recipes
Recipe 1 Recipe 2
App
Recipes Add Recipe
Recipe 1 Recipe 2
State to React
Store
Recipes
Recipe 1 Recipe 2
App
Recipes Add Recipe
Recipe 1 Recipe 2
Connect




connect()(App);

Connect
function mapStateToProps(state) { 

return {};

}



function mapDispatchToProps(dispath) {

return {};

}



connect(mapStateToProps, mapDispatchToProps)(App);

MUTATE STATE
OUR STATE
State
Recipes
Omelette Pancaek
User
Boris
T1
The reducer
action = {

type: 'RENAME_RECIPE',

recipeId: 871,

name: 'Pancake'

};
const reducer = (state, action) => {

switch (action.type) {

case ‘RENAME_RECIPE':

const { recipeId, newName } = action;

state.recipes[recipeId].name = newName;

return state;

}

return state;

};
The reducer
action = {

type: 'RENAME_RECIPE',

recipeId: 871,

name: 'Pancake'

};
const reducer = (state, action) => {

switch (action.type) {

case ‘RENAME_RECIPE':

const { recipeId, newName } = action;

state.recipes[recipeId].name = newName;

return state;

}

return state;

};
The reducer
const reducer = (state, action) => {

switch (action.type) {

case ‘RENAME_RECIPE':

const recipe = state.recipes[action.recipeId];



const newRecipe = Object.assign({}, recipe, {

name: action.newName

});



const newRecipes = Object.assign({}, state.recipes, {

[action.recipeId]: newRecipe

});



return Object.assign({}, state, {

recipes: newRecipes

});

}

return state;

};



Object.assign()
const original = {

name: 'Cat',

age: 3

};



const updated = Object.assign({}, original, {

name: 'Dog'

});
updated

> { name: 'Dog', age: 3 }



updated === original

> false
REFERENCE TREES
State
Recipes
Omelette Pancaek
User
Boris
T1
Pancake
T2
REFERENCE TREES
State
Recipes
Omelette Pancaek
User
Boris
T1
Recipes
Omelette Pancake
T2
REFERENCE TREES
State
Recipes
Omelette Pancaek
User
Boris
T1
State
Recipes
Omelette Pancake
User
Boris
T2
IN MEMORY
State
Recipes
Omelette Pancaek
User
Boris
State
Recipes
Pancake
T1 T2
ACTION #2
State
Recipes
Omelette Pancaek
User
Boris
State
Recipes
Omelett Pancake
User
Boris
T1 T2
State
Recipes
Bacon Pancake
User
Boris
T3
IN MEMORY
State
Recipes
Omelette Pancaek
User
Boris
State
Recipes
Pancake
State
Recipes
Bacon
T1 T2 T3
Why not direct?
state.recipes[recipeId].name = newName;
OH, NO!
State
Recipes
Omelette Pancaek
User
Boris
State
Recipes
Pancake
State
Recipes
Bacon
T1 T2 T3
Omelett
User
Boris
User
Cat Pancake
OUT SIDE CHANGE
State
Recipes
Omelette Pancaek
User
Cat
State
Recipes
Pancake
State
Recipes
Bacon
T1 T2 T3
OH, NO!
State
Recipes
Omelette Pancaek
User
Cat
State
Recipes
Pancake
State
Recipes
Bacon
T1 T2 T3
Omelett
User
Cat
User
Cat Pancake
Console work
s1 = store.getState()
- Do an action
s2 = store.getState()
- Do an action
s3 = store.getState()
store.dispatch({ type: ‘SET_STATE’, payload: s1 });
Console work
s1 = store.getState()
- Do an action
s2 = store.getState()
- Do an action
s3 = store.getState()
store.dispatch({ type: ‘SET_STATE’, payload: s1 });
Console work
s1 = store.getState()
- Do an action
s2 = store.getState()
- Do an action
s3 = store.getState()
store.dispatch({ type: ‘SET_STATE’, payload: s1 });
Console work
s1 = store.getState()
- Do an action
s2 = store.getState()
- Do an action
s3 = store.getState()
store.dispatch({ type: ‘SET_STATE’, payload: s1 });
UNDO / REDO
BUT…
1. Actions like LOGIN
2. Actions from Middleware / Redux-Thunk
3. Layout / UI
Directory structure
reducers
store
components
ACTION CREATORS
Actions
export const addRecipe = (name) => ({

type: 'ADD_RECIPE',

name: name

});
ROUTING
React Router
import { Router, Route, browserHistory } from 'react-router'



render(

<Provider store={ store }>

<Router history={ browserHistory }>

<Route path="" components={ App }>

<Route path="/add" component={ AddRecipe } />

<Route path="/" component={ Recipes } />

</Route>

<Route path="*" component={ NotFound } />

</Router>

</Provider>,

document.getElementById('app')

);
TESTS
Testing
Karma - Test running - https://karma-runner.github.io/0.13/index.html
Enzyme - Test utils for React - https://github.com/airbnb/enzyme
Jasmine - Matcher and mocks - http://ricostacruz.com/cheatsheets/jasmine.html
Redux tests - http://redux.js.org/docs/recipes/WritingTests.html
SUMMARY
Useful stuff
Meetup: http://www.meetup.com/ReactJS-Israel/
Redux tutorial: https://egghead.io/series/getting-started-with-redux
The code we built: https://bitbucket.org/500tech/react-redux-course
Introduction to React & Redux
Read our blog:
http://blog.500tech.com
React & Redux

More Related Content

What's hot (20)

PDF
Introduction to Redux
Ignacio Martín
 
PDF
Let's discover React and Redux with TypeScript
Mathieu Savy
 
PDF
React state managmenet with Redux
Vedran Blaženka
 
PDF
Designing applications with Redux
Fernando Daciuk
 
PPTX
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
PDF
Intro to ReactJS
Harvard Web Working Group
 
PPTX
Redux training
dasersoft
 
PPTX
Introduction to react and redux
Cuong Ho
 
PDF
Redux js
Nils Petersohn
 
PPTX
React with Redux
Stanimir Todorov
 
PPTX
React / Redux Architectures
Vinícius Ribeiro
 
PDF
Intro to Redux | DreamLab Academy #3
DreamLab
 
PDF
Quick start with React | DreamLab Academy #2
DreamLab
 
PPTX
Better web apps with React and Redux
Ali Sa'o
 
PDF
Building React Applications with Redux
FITC
 
PDF
Redux vs Alt
Uldis Sturms
 
PDF
React & Redux
Craig Jolicoeur
 
PDF
Advanced redux
Boris Dinkevich
 
PPTX
React & redux
Cédric Hartland
 
PDF
React redux
Michel Perez
 
Introduction to Redux
Ignacio Martín
 
Let's discover React and Redux with TypeScript
Mathieu Savy
 
React state managmenet with Redux
Vedran Blaženka
 
Designing applications with Redux
Fernando Daciuk
 
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
Intro to ReactJS
Harvard Web Working Group
 
Redux training
dasersoft
 
Introduction to react and redux
Cuong Ho
 
Redux js
Nils Petersohn
 
React with Redux
Stanimir Todorov
 
React / Redux Architectures
Vinícius Ribeiro
 
Intro to Redux | DreamLab Academy #3
DreamLab
 
Quick start with React | DreamLab Academy #2
DreamLab
 
Better web apps with React and Redux
Ali Sa'o
 
Building React Applications with Redux
FITC
 
Redux vs Alt
Uldis Sturms
 
React & Redux
Craig Jolicoeur
 
Advanced redux
Boris Dinkevich
 
React & redux
Cédric Hartland
 
React redux
Michel Perez
 

Viewers also liked (11)

PDF
Using ReactJS in AngularJS
Boris Dinkevich
 
PDF
React and redux
Mystic Coders, LLC
 
PDF
An Introduction to ReactJS
All Things Open
 
PPTX
A Brief Introduction to React.js
Doug Neiner
 
PPTX
Reactjs
Neha Sharma
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
Redux with angular 2 - workshop 2016
Nir Kaufman
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PDF
Getting Started with React
Nathan Smith
 
PDF
React JS and why it's awesome
Andrew Hull
 
PPT
React js
Jai Santhosh
 
Using ReactJS in AngularJS
Boris Dinkevich
 
React and redux
Mystic Coders, LLC
 
An Introduction to ReactJS
All Things Open
 
A Brief Introduction to React.js
Doug Neiner
 
Reactjs
Neha Sharma
 
ReactJS presentation
Thanh Tuong
 
Redux with angular 2 - workshop 2016
Nir Kaufman
 
React + Redux Introduction
Nikolaus Graf
 
Getting Started with React
Nathan Smith
 
React JS and why it's awesome
Andrew Hull
 
React js
Jai Santhosh
 
Ad

Similar to Introduction to React & Redux (20)

PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
React & Redux for noobs
[T]echdencias
 
PDF
react-hooks.pdf
chengbo xu
 
PDF
Workshop React.js
Commit University
 
PDF
Integrating React.js with PHP projects
Ignacio Martín
 
PDF
Materi Modern React Redux Power Point.pdf
exiabreak
 
PDF
The Functional Programming Toolkit (NDC Oslo 2019)
Scott Wlaschin
 
PPTX
Combining Angular and React Together
Sebastian Pederiva
 
PPTX
Intro react js
Vijayakanth MP
 
PDF
React & The Art of Managing Complexity
Ryan Anklam
 
PPTX
Build web apps with react js
dhanushkacnd
 
PDF
Introduction to react
kiranabburi
 
PPT
Lec9Handout.ppt
MOMEKEMKUEFOUETDUREL
 
PPTX
Painless Migrations from Backbone to React/Redux
Jim Sullivan
 
PDF
React Native - Getting Started
Tracy Lee
 
PDF
Server side rendering with React and Symfony
Ignacio Martín
 
PPTX
React outbox
Angela Lehru
 
PPTX
Getting Started with React v16
Benny Neugebauer
 
PPTX
React 16: new features and beyond
Artjoker
 
PDF
Workshop 19: ReactJS Introduction
Visual Engineering
 
[Final] ReactJS presentation
洪 鹏发
 
React & Redux for noobs
[T]echdencias
 
react-hooks.pdf
chengbo xu
 
Workshop React.js
Commit University
 
Integrating React.js with PHP projects
Ignacio Martín
 
Materi Modern React Redux Power Point.pdf
exiabreak
 
The Functional Programming Toolkit (NDC Oslo 2019)
Scott Wlaschin
 
Combining Angular and React Together
Sebastian Pederiva
 
Intro react js
Vijayakanth MP
 
React & The Art of Managing Complexity
Ryan Anklam
 
Build web apps with react js
dhanushkacnd
 
Introduction to react
kiranabburi
 
Lec9Handout.ppt
MOMEKEMKUEFOUETDUREL
 
Painless Migrations from Backbone to React/Redux
Jim Sullivan
 
React Native - Getting Started
Tracy Lee
 
Server side rendering with React and Symfony
Ignacio Martín
 
React outbox
Angela Lehru
 
Getting Started with React v16
Benny Neugebauer
 
React 16: new features and beyond
Artjoker
 
Workshop 19: ReactJS Introduction
Visual Engineering
 
Ad

Recently uploaded (20)

PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 

Introduction to React & Redux