SlideShare a Scribd company logo
1 of 35
React, Flux and a little bit of
Redux
By Ny Fanilo Andrianjafy
React
My previous experiences
I found out about it in 2014.
The concept made a lot of sense to
me.
Then I laid eyes on some code.
2
var HelloMessage = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
ReactDOM.render(<HelloMessage name="John" />,
mountNode);
3
And I hated it.
4
React
My previous experiences
I began a project with web
components and it was not ready
at that time.
The founder of player.me
convinced me to check it again
and look past the weird syntax.
5
React is a JavaScript library to build
UIs.
Only the UI
Virtual DOM
One-Way binding
Characteristics
Uses JSX
You build components
Should be Reusable
Can be Stateful
Have a Lifecycle
Containers / Subcomponents
What is React ?
6
React
Components
The lifecycle
componentWillMount: Before the initial rendering.
componentDidMount: After the initial rendering.
componentWillReceiveProps: When receiving new
props.
componentWillUpdate: When about to update avec
receiving new props.
componentDidUpdate: Invoked after the component
updates.
componentWillUnmount: Before unmounting from
the DOM.
7
Let’s take 5 minutes for a ES2015 crash
course
8
// ES5
var quadratic = function(a, b, c) {
return function(x) {
return (a * x * x) + (b * x) + c;
};
};
// ES2015
let quadratic = (a, b, c) => (x) => (a * x * x) + (b * x) + c;
9
// ES5
var myObject = { a: 1, b: 2, c: 3 };
var a = myObject.a;
var foo = myObject.b;
// ES2015
let myObject = { a: 1, b: 2, c: 3 };
let { a, b: foo } = myObject;
10
// ES5
var myArray = [1, 2, 3, 4, 5, 6];
var x = myArray[0];
var y = myArray[4];
// ES2015
let myArray = [1, 2, 3, 4, 5, 6];
let [x,,,,y] = myArray;
11
// ES5
var world = 'World';
var myValue = 'Hello ' + world + ' ! This is a string template.';
// ES2015
let world = 'World';
let myValue = `Hello ${world} ! This is a string template.`;
12
// ES5
var a = 123;
var b = 456;
var c = {
a: a,
b: b,
foo: 'bar'
};
// ES2015
let a = 123;
let b = 456
let c = {
a,
b,
foo: 'bar'
};
13
(state = [], action) => {
return state.map(action);
}
14
JSX
15
Markup that looks like HTML that
gets transformed to JavaScript
functions.
You do not have to use it when
writing React applications.
They are shorthands to call
React.createElement().
Built against XSS attacks
It is not a HTML templating language
Do not put them in the same bucket as
Handlebars or Mustache. It is not
simply token replacing.
Declarative syntax to express Virtual
DOM.
Virtual DOM is diffed with the real
DOM and re-rendered efficiently.
Not limited to HTML.
JSX
16
<!-- HTML and JavaScript belong together. -->
<!-- Right now, we put JavaScript in our HTML files. -->
<form data-bind="submit: addItem">
New item:
<input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' />
<button type="submit" data-bind="enable: itemToAdd().length > 0">Add</button>
<p>Your items:</p>
<select multiple="multiple" data-bind="options: items"> </select>
</form>
17
// JSX reverses the context and puts HTML in your JavaScript.
var Form = React.createClass({
[...]
render: function() {
var options = this.renderOptions();
return (
<div>
New Item: <input type="text" onChange={this.handleChange} ref="itemToAdd"/>
<button type="submit" disabled={!this.state.itemToAdd} onClick={this.addItem}>Add</button><br />
Your Items:<br />
<select multiple="multiple">
{options}
</select>
</div>
);
}
});
18
var HelloMessage = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
ReactDOM.render(<HelloMessage name="John" />,
mountNode);
19
"use strict";
var HelloMessage = React.createClass({
displayName: "HelloMessage",
render: function render() {
return React.createElement(
"div",
null,
"Hello ",
this.props.name
);
}
});
ReactDOM.render(React.createElement(HelloMessage, { name: "John" }), mountNode);
20
The Good:
Since the markup is compiled to
functions, malformatted JSX will
fail at compilation time.
JavaScript is more powerful than
HTML, so you use the full power
of JavaScript to build your UI.
UI is testable.
Rendering is faster because of the
Virtual DOM.
The Bad:
Harsh first impression.
JSX
21
Flux
22
Flux
23
Flux is an architecture for client-side applications.
Do not consider it as a framework, even though there is a framework called flux.
The data flow is unidirectional.
Four major parts:
Stores
Actions
Dispatcher
Views
Flux
24
Flux: Stores
Holds the logic and state of the
application.
25
Flux: Stores
Action creators create payloads that explains
what happened.
26
Flux: Dispatcher
Acts as the central hub of the data flow. Stores
register callback to the dispatcher and it invokes
them when it receives actions
27
Flux: Dispatcher
Views listen to the store and display their
data.
28
Redux
29
State container for JavaScript applications
Not limited to React
You can use it with any View library
Took cues from elm
Not totally Flux but not very far from it.
Redux
30
let initialState = { items: [] };
(state = initialState, action) => {
return Object.assign({}, state, {
items: state.items.concat([action.note])
});
}
31
(oldState, action) => newState
No Mutation.
32
One store to rule them all.
33
Actions are very simple objects or
functions when doing async operations
34
Conclusion
React is evolutionary
Virtual DOM is fast.
Think in terms of functions.
Presentation only.
Flux makes the application state more predictable and easier to reason about
Redux brings a nice functional programming flavor.
Where to go next:
React Native
35

More Related Content

What's hot

Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with ReduxFernando Daciuk
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overviewAlex Bachuk
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 
React – Structure Container Component In Meteor
 React – Structure Container Component In Meteor React – Structure Container Component In Meteor
React – Structure Container Component In MeteorDesignveloper
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with ReduxVedran Blaženka
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Let's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptMathieu Savy
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developerEugene Zharkov
 

What's hot (20)

React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
React and redux
React and reduxReact and redux
React and redux
 
Workshop React.js
Workshop React.jsWorkshop React.js
Workshop React.js
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
React js
React jsReact js
React js
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
React – Structure Container Component In Meteor
 React – Structure Container Component In Meteor React – Structure Container Component In Meteor
React – Structure Container Component In Meteor
 
React & redux
React & reduxReact & redux
React & redux
 
ReactJS
ReactJSReactJS
ReactJS
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Let's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScript
 
React & Flux Workshop
React & Flux WorkshopReact & Flux Workshop
React & Flux Workshop
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 

Similar to React, Flux and a little bit of Redux

Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
React - An Introduction
React - An IntroductionReact - An Introduction
React - An IntroductionTyler Johnston
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For ManagersAgileThought
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015jbandi
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy Goh
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React TogetherSebastian Pederiva
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web DevelopmentFITC
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_twTse-Ching Ho
 
5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScriptNael El Shawwa
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JSBinary Studio
 

Similar to React, Flux and a little bit of Redux (20)

Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
React - An Introduction
React - An IntroductionReact - An Introduction
React - An Introduction
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
ReactJS
ReactJSReactJS
ReactJS
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
React js
React jsReact js
React js
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React Together
 
Functional Web Development
Functional Web DevelopmentFunctional Web Development
Functional Web Development
 
20150516 modern web_conf_tw
20150516 modern web_conf_tw20150516 modern web_conf_tw
20150516 modern web_conf_tw
 
5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript5 Tips for Writing Better JavaScript
5 Tips for Writing Better JavaScript
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JS
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 

Recently uploaded

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 

Recently uploaded (20)

WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

React, Flux and a little bit of Redux

  • 1. React, Flux and a little bit of Redux By Ny Fanilo Andrianjafy
  • 2. React My previous experiences I found out about it in 2014. The concept made a lot of sense to me. Then I laid eyes on some code. 2
  • 3. var HelloMessage = React.createClass({ render: function() { return <div>Hello {this.props.name}</div>; } }); ReactDOM.render(<HelloMessage name="John" />, mountNode); 3
  • 4. And I hated it. 4
  • 5. React My previous experiences I began a project with web components and it was not ready at that time. The founder of player.me convinced me to check it again and look past the weird syntax. 5
  • 6. React is a JavaScript library to build UIs. Only the UI Virtual DOM One-Way binding Characteristics Uses JSX You build components Should be Reusable Can be Stateful Have a Lifecycle Containers / Subcomponents What is React ? 6
  • 7. React Components The lifecycle componentWillMount: Before the initial rendering. componentDidMount: After the initial rendering. componentWillReceiveProps: When receiving new props. componentWillUpdate: When about to update avec receiving new props. componentDidUpdate: Invoked after the component updates. componentWillUnmount: Before unmounting from the DOM. 7
  • 8. Let’s take 5 minutes for a ES2015 crash course 8
  • 9. // ES5 var quadratic = function(a, b, c) { return function(x) { return (a * x * x) + (b * x) + c; }; }; // ES2015 let quadratic = (a, b, c) => (x) => (a * x * x) + (b * x) + c; 9
  • 10. // ES5 var myObject = { a: 1, b: 2, c: 3 }; var a = myObject.a; var foo = myObject.b; // ES2015 let myObject = { a: 1, b: 2, c: 3 }; let { a, b: foo } = myObject; 10
  • 11. // ES5 var myArray = [1, 2, 3, 4, 5, 6]; var x = myArray[0]; var y = myArray[4]; // ES2015 let myArray = [1, 2, 3, 4, 5, 6]; let [x,,,,y] = myArray; 11
  • 12. // ES5 var world = 'World'; var myValue = 'Hello ' + world + ' ! This is a string template.'; // ES2015 let world = 'World'; let myValue = `Hello ${world} ! This is a string template.`; 12
  • 13. // ES5 var a = 123; var b = 456; var c = { a: a, b: b, foo: 'bar' }; // ES2015 let a = 123; let b = 456 let c = { a, b, foo: 'bar' }; 13
  • 14. (state = [], action) => { return state.map(action); } 14
  • 16. Markup that looks like HTML that gets transformed to JavaScript functions. You do not have to use it when writing React applications. They are shorthands to call React.createElement(). Built against XSS attacks It is not a HTML templating language Do not put them in the same bucket as Handlebars or Mustache. It is not simply token replacing. Declarative syntax to express Virtual DOM. Virtual DOM is diffed with the real DOM and re-rendered efficiently. Not limited to HTML. JSX 16
  • 17. <!-- HTML and JavaScript belong together. --> <!-- Right now, we put JavaScript in our HTML files. --> <form data-bind="submit: addItem"> New item: <input data-bind='value: itemToAdd, valueUpdate: "afterkeydown"' /> <button type="submit" data-bind="enable: itemToAdd().length > 0">Add</button> <p>Your items:</p> <select multiple="multiple" data-bind="options: items"> </select> </form> 17
  • 18. // JSX reverses the context and puts HTML in your JavaScript. var Form = React.createClass({ [...] render: function() { var options = this.renderOptions(); return ( <div> New Item: <input type="text" onChange={this.handleChange} ref="itemToAdd"/> <button type="submit" disabled={!this.state.itemToAdd} onClick={this.addItem}>Add</button><br /> Your Items:<br /> <select multiple="multiple"> {options} </select> </div> ); } }); 18
  • 19. var HelloMessage = React.createClass({ render: function() { return <div>Hello {this.props.name}</div>; } }); ReactDOM.render(<HelloMessage name="John" />, mountNode); 19
  • 20. "use strict"; var HelloMessage = React.createClass({ displayName: "HelloMessage", render: function render() { return React.createElement( "div", null, "Hello ", this.props.name ); } }); ReactDOM.render(React.createElement(HelloMessage, { name: "John" }), mountNode); 20
  • 21. The Good: Since the markup is compiled to functions, malformatted JSX will fail at compilation time. JavaScript is more powerful than HTML, so you use the full power of JavaScript to build your UI. UI is testable. Rendering is faster because of the Virtual DOM. The Bad: Harsh first impression. JSX 21
  • 24. Flux is an architecture for client-side applications. Do not consider it as a framework, even though there is a framework called flux. The data flow is unidirectional. Four major parts: Stores Actions Dispatcher Views Flux 24
  • 25. Flux: Stores Holds the logic and state of the application. 25
  • 26. Flux: Stores Action creators create payloads that explains what happened. 26
  • 27. Flux: Dispatcher Acts as the central hub of the data flow. Stores register callback to the dispatcher and it invokes them when it receives actions 27
  • 28. Flux: Dispatcher Views listen to the store and display their data. 28
  • 30. State container for JavaScript applications Not limited to React You can use it with any View library Took cues from elm Not totally Flux but not very far from it. Redux 30
  • 31. let initialState = { items: [] }; (state = initialState, action) => { return Object.assign({}, state, { items: state.items.concat([action.note]) }); } 31
  • 32. (oldState, action) => newState No Mutation. 32
  • 33. One store to rule them all. 33
  • 34. Actions are very simple objects or functions when doing async operations 34
  • 35. Conclusion React is evolutionary Virtual DOM is fast. Think in terms of functions. Presentation only. Flux makes the application state more predictable and easier to reason about Redux brings a nice functional programming flavor. Where to go next: React Native 35