SlideShare a Scribd company logo
Intro to React & Redux
Boris Dinkevich
http://500Tech.com
boris@500tech.com
Remember this day
Boris Dinkevich
- 4 years Dev Ops
- 4 years Embedded C
- 4 years Ruby on Rails
- 4 years JavaScript (Angular/React)
Developing stuff
Boris Dinkevich
- AngularJS Israel (4K ppl)
- ReactJS Israel (2K ppl)
- Angular UP
- React Next
- React Courses
- Figuring what tech ppl do in NYC??
These days
Introduction to ReactJS and Redux
ES2015 (ES6)
Const & Let
Strings
Arrow functions
Destructuring
A WORD ON TOOLS
npm - package repository
babel - transpiler
webpack - build tool
yarn - package repository
babel - transpiler
webpack - build tool
Create React App
https://github.com/facebookincubator/create-react-app
BACK TO REACT
HISTORY
Component Driven Development
COMPONENTS
Introduction to ReactJS and Redux
Introduction to ReactJS and Redux
Introduction to ReactJS and Redux
Introduction to ReactJS and Redux
Thinking in components
Thinking in components
COMPONENT INNARDS
Whats inside?
Component
Props
State
Main
Props
State
Footer
State
Header
State
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
Virtual DOM
Recipe
Ingredients
Eggs
Real DOM
=
Recipe
Ingredients
Eggs
Recipe
Ingredients
Eggs
Virtual DOM
Real DOM
Recipe
Ingredients
Eggs
Recipe
Ingredients
MilkEggs
New Virtual DOM
Recipe
Ingredients
Eggs
Old Virtual DOM
Real DOM
!=
Recipe
Ingredients
Eggs
Recipe
Ingredients
MilkEggs
New Virtual DOM
Recipe
Ingredients
Eggs
Old Virtual DOM
Real DOM
Milk
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')

]);

}


const App() = (

<div>

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

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

</div>

);

PROPS
Component
Props
State
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
FLUX
MVC
FLUX
Introduction to ReactJS and Redux
Chat
Notifications
Messages
Page Title
Chat
Notifications
Messages
Page Title
Data
Flux
Components
Dispatcher
ActionsStores
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
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
ROUTING
React Router
import { Router, Route, browserHistory } from 'react-router'



render(

<Provider store={ store }>

<Router history={ browserHistory }>

..routes..


</Router>

</Provider>,

document.getElementById('app')

);
React Router


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

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

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

</Route>

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

REACT NATIVE
const HelloWeb = ({ name }) => (
<div>
<p>
Hello { name }
</p>
</div>
);
const HelloNative = ({ name }) => (
<View>
<Text>
Hello { name }
</Text>
</View>
);
One code
iOS
Android
Web
* MacOS
* Windows
* More?
Auto updates
No Apple Store / Google Play resubmit
Think of the bug solving!
SERVER RENDERING
Fetch
index.html
Parse & Show
Fetch JS
App & React
Load JS
Run React
AJAX
Update UI
Fetch
index.html
Parse & Show
time
Fetch
index.html
Parse & Show
Fetch JS
App & React
Load JS
Run React
AJAX
Update UI
Fetch
index.html
Parse & Show
Fetch JS
App & React
Load JS
Run React
Update UI Clickable
time
Load App
Local AJAX
Render to HTML
& JSON
Cachable
TESTS
Testing
Jest - Test framework - https://facebook.github.io/jest/
Enzyme - Test utils for React - https://github.com/airbnb/enzyme
Redux tests - http://redux.js.org/docs/recipes/WritingTests.html
SUMMARY
THE COMPLETE
REDUX BOOK
Read our blog:
http://blog.500tech.com
React & Redux

More Related Content

PDF
Advanced redux
PDF
Reduxing like a pro
PDF
Introduction to React & Redux
PDF
React + Redux. Best practices
PDF
React lecture
PDF
Quick start with React | DreamLab Academy #2
PDF
Intro to Redux | DreamLab Academy #3
PDF
Evan Schultz - Angular Camp - ng2-redux
Advanced redux
Reduxing like a pro
Introduction to React & Redux
React + Redux. Best practices
React lecture
Quick start with React | DreamLab Academy #2
Intro to Redux | DreamLab Academy #3
Evan Schultz - Angular Camp - ng2-redux

What's hot (20)

PDF
Evan Schultz - Angular Summit - 2016
PDF
Switch to React.js from AngularJS developer
PDF
Integrating React.js with PHP projects
PDF
Designing applications with Redux
PDF
Reactive.architecture.with.Angular
PPTX
Redux training
PDF
Introduction to Redux
PPTX
Getting started with ReactJS
PDF
Redux vs Alt
PDF
React on es6+
PDF
State Models for React with Redux
PDF
Let's discover React and Redux with TypeScript
PPTX
Better React state management with Redux
PPTX
React with Redux
PDF
React & Redux
PDF
React redux
PPTX
ProvJS: Six Months of ReactJS and Redux
PDF
React state managmenet with Redux
PPTX
Introduction to react and redux
PDF
Angular2 & ngrx/store: Game of States
Evan Schultz - Angular Summit - 2016
Switch to React.js from AngularJS developer
Integrating React.js with PHP projects
Designing applications with Redux
Reactive.architecture.with.Angular
Redux training
Introduction to Redux
Getting started with ReactJS
Redux vs Alt
React on es6+
State Models for React with Redux
Let's discover React and Redux with TypeScript
Better React state management with Redux
React with Redux
React & Redux
React redux
ProvJS: Six Months of ReactJS and Redux
React state managmenet with Redux
Introduction to react and redux
Angular2 & ngrx/store: Game of States
Ad

Similar to Introduction to ReactJS and Redux (20)

PPTX
React + Redux Introduction
PDF
Materi Modern React Redux Power Point.pdf
PDF
Building Universal Web Apps with React ForwardJS 2017
PPT
Lec9Handout.ppt
PDF
React Lifecycle and Reconciliation
PPTX
Combining Angular and React Together
PDF
Workshop React.js
PDF
Server side rendering with React and Symfony
PDF
Reactивная тяга
PPT
Lec7Handout.ppt
PDF
OttawaJS - React
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
Workshop 22: React-Redux Middleware
PDF
Workshop 22: ReactJS Redux Advanced
PPTX
Introduction to react_js
PPTX
React - Start learning today
PDF
End to end todo list app with NestJs - Angular - Redux & Redux Saga
PDF
React js
PDF
Redux with angular 2 - workshop 2016
PPTX
Build web apps with react js
React + Redux Introduction
Materi Modern React Redux Power Point.pdf
Building Universal Web Apps with React ForwardJS 2017
Lec9Handout.ppt
React Lifecycle and Reconciliation
Combining Angular and React Together
Workshop React.js
Server side rendering with React and Symfony
Reactивная тяга
Lec7Handout.ppt
OttawaJS - React
Academy PRO: React JS. Redux & Tooling
Workshop 22: React-Redux Middleware
Workshop 22: ReactJS Redux Advanced
Introduction to react_js
React - Start learning today
End to end todo list app with NestJs - Angular - Redux & Redux Saga
React js
Redux with angular 2 - workshop 2016
Build web apps with react js
Ad

Recently uploaded (20)

PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
PPTX
Introduction to Artificial Intelligence
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PPTX
Presentation of Computer CLASS 2 .pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
DOCX
The Five Best AI Cover Tools in 2025.docx
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
AIRLINE PRICE API | FLIGHT API COST |
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
System and Network Administration Chapter 2
PPTX
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Online Work Permit System for Fast Permit Processing
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
AI in Product Development-omnex systems
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Introduction to Artificial Intelligence
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Presentation of Computer CLASS 2 .pptx
Transform Your Business with a Software ERP System
Which alternative to Crystal Reports is best for small or large businesses.pdf
The Five Best AI Cover Tools in 2025.docx
Materi-Enum-and-Record-Data-Type (1).pptx
PTS Company Brochure 2025 (1).pdf.......
VVF-Customer-Presentation2025-Ver1.9.pptx
Understanding Forklifts - TECH EHS Solution
AIRLINE PRICE API | FLIGHT API COST |
Softaken Excel to vCard Converter Software.pdf
ManageIQ - Sprint 268 Review - Slide Deck
System and Network Administration Chapter 2
Mastering-Cybersecurity-The-Crucial-Role-of-Antivirus-Support-Services.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Online Work Permit System for Fast Permit Processing
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
AI in Product Development-omnex systems

Introduction to ReactJS and Redux