SlideShare a Scribd company logo
1 of 51
Download to read offline
ReactJS
The future of web development
Thanh Tuong | ReactJS | 2016
1
Thanh Tuong | ReactJS | 2016
2
https://github.com/facebook/react/wiki/Sites-Using-React
History
 In 2010, Facebook released an extension for PHP called XHP.
 XHP help to decrease XSS attack and make front-end much both readable
and understand.
Thanh Tuong | ReactJS | 2016
<?php
if ($_POST['name']) {
echo <span>Hello,
{$_POST['name']}</span>;
} else {
echo
<form method="post">
What is your name?<br />
<input type="text" name="name" />
<input type="submit" />
</form>;
}
<?php
if ($_POST['name']) {
?>
<span>Hello, <?=$_POST['name']?>.</span>
<?php
} else {
?>
<form method="post">
What is your name?<br>
<input type="text" name="name">
<input type="submit">
</form>
<?php
}
PHP XHP
3
History (cont)
 But…
 There was a distinct problem with XHP: dynamic web applications require
many roundtrips to the server.
 XHP did not solve this problem.
 A Facebook engineer negotiated with his manager to take XHP into the
browser using JavaScript and was granted six months to try it.
 And…
Thanh Tuong | ReactJS | 2016
4
React was
born
ReactJS {purpose}
 Creating user interface(V in MVC model).
 Building large applications with data that changes over time.
Thanh Tuong | ReactJS | 2016
5
var React = React.createClass({
render: function() {
return (
<h1> Hello React </h1>
);
}
});
ReactDOM.render(<React />,document.getElementById('container'));
Syntax
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
6
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
7
ReactJS {JSX}
 JSX is a JavaScript syntax extension that looks similar to XML.
 Concise and familiar syntax for defining tree structures with attributes.
 Make large trees easier to read than function calls or object literals.
 Can be used in both HTML tags and Components.
Thanh Tuong | ReactJS | 2016
8
ReactJS {JSX – examples}
 HTML tags
 var myDivElement = <div className="foo" > HTML tags </div>;
 ReactDOM.render(myDivElement, document.getElementById('example'));
 Component
 var MyComponent = React.createClass({/*...*/});
 var myElement = <MyComponent />;
 ReactDOM.render(myElement, document.getElementById('example'));
Thanh Tuong | ReactJS | 2016
9
ReactJS {JSX – examples (cont)}
 HTML tags (without JSX)
 var myDivElement = React.createElement('div', {className: 'foo'}, 'HTML tags');
 ReactDOM.render(myDivElement, document.getElementById('example'));
 Component (without JSX)
var MyComponent = React.createClass({
render: function() {
return (
React.createElement('h1',{}, 'Component without JSX')
);
}
});
var myElement = <MyComponent />;
ReactDOM.render(myElement, document.getElementById('content'));
Thanh Tuong | ReactJS | 2016
10
ReactJS {JSX – Transform}
 React JSX transforms from an XML-like syntax into native JavaScript.
 XML elements, attributes and children are transformed into arguments that
are passed to React.createElement.
Thanh Tuong | ReactJS | 2016
11
Children
ReactJS {JSX –Namespaced}
 What if you are building a component with many children? For example
Form.
 Namespaced components help to make component simpler and easier.
 You just need to create your "sub-components" as attributes of the main
component.
Thanh Tuong | ReactJS | 2016
12
ReactJS {JSX –Namespaced (cont)}
Thanh Tuong | ReactJS | 2016
13
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
14
ReactJS {Virtual-DOM}
 Problem:
 DOM manipulation is expensive.
 Re-render all parts of DOM make your app slowly.
 When the component’s state is changed, React will compare with DOM
element to make smallest change.
 Is made by React.createElement().
 https://www.youtube.com/watch?v=BYbgopx44vo
Thanh Tuong | ReactJS | 2016
15
ReactJS {Virtual-DOM}
Thanh Tuong | ReactJS | 2016
16
Only diff changes
from the two V-DOMs
are applied to real
DOM
ReactJS {Virtual-DOM (cont)}
 1. Backbone.js recontruct
DOM elements marked as
“change”.
 2. Backbone.js recontruct
All DOM elements.
 3. ReactJS recontruct DOM
elements base on calculate the
difference.
Thanh Tuong | ReactJS | 2016
17
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
18
ReactJS {props}
 Used to pass parameter from parent to children.
 var HelloReact = React.createClass({
render: function() {
return (
<h1> Hello, {this.props.name} </h1>
);
}
});
ReactDOM.render(<HelloReact name="ReactJS!!!" />, node);
Thanh Tuong | ReactJS | 2016
19
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
20
ReactJS {PropTypes}
 For validate the prop’s value input.
 var HelloReact = React.createClass({
propTypes: {
name: React.PropTypes.number
},
render: function() {
return (
<h1> Hello, {this.props.name} </h1>
);
}
});
ReactDOM.render(<HelloReact name="thanh" />, document.getElementById('content'));
Thanh Tuong | ReactJS | 2016
21
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
22
ReactJS {state}
 To manage state inside component.
 getInitialState() function: init value for variable.
 setState() function: update new value for variable.
Thanh Tuong | ReactJS | 2016
23
ReactJS {state-(cont)}
 When you should use state?
 Respond to user input.
 Server request.
 or the passage of time.
Thanh Tuong | ReactJS | 2016
24
ReactJS { props vs state }
Features props state
Can get initial value from
parent Component?
Yes Yes
Can be changed by
parent Component?
Yes No
Can set default values
inside Component?
Yes Yes
Can change inside
Component?
No Yes
Can set initial value for
child Components?
Yes Yes
Can change in child
Components?
Yes No
Thanh Tuong | ReactJS | 2016
25
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
26
ReactJS {refs}
 How we make focus to input element after clear data from input element?
 How we can make a search with many criteria ?
 …
Thanh Tuong | ReactJS | 2016
27
Refs
ReactJS {refs-(cont)}
Thanh Tuong | ReactJS | 2016
28
Type…
Click clear
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
29
ReactJS {LifeCycle}
 Each component has its own lifecycle events.
 Ex:
 If we wanted to make an ajax request on the initial render and fetch some data,
where would we do that?
 If we wanted to run some logic whenever our props changed, how would we do
that?
 …
Thanh Tuong | ReactJS | 2016
30
LifeCycle
events
ReactJS {LifeCycle (cont)}
 componentWillMount
 Invoked once (both on the client and server ) before the initial render.
 Good place to make connection to your db service (ex: firebase,...)
 Do not call set state method here.
Thanh Tuong | ReactJS | 2016
31
ReactJS {LifeCycle (cont)}
 componentDidMount
 Invoked once, only on the client (not on the server).
 Immediately after the initial rendering occurs.
 It is good place for you to make AJAX request to fetch data for first used.
Thanh Tuong | ReactJS | 2016
32
ReactJS {LifeCycle (cont)}
 componentWillReceiveProps
 Invoked when a component is receiving new props.
 This method is not called for the initial render.
 Use this method as a way to react to a prop change before render() is called by
updating the state with setState.
Thanh Tuong | ReactJS | 2016
33
ReactJS {LifeCycle (cont)}
 componentWillUnmount
 Invoked immediately before a component is unmounted from the DOM.
 Perform any necessary cleanup in this method(Ex: invalidating timers, clear up
DOM elements were created at componentDidMount)
Thanh Tuong | ReactJS | 2016
34
Nothing!!!
http://facebook.github.io/react/docs/component-
specs.html
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Thinking in React
 Routing
Thanh Tuong | ReactJS | 2016
35
ReactJS {Flux}
 Flux is the application architecture.
 Making data changes easy.
 Remove the burden of having a component manage its own state.
 The data is moved to the central called Store.
 If your app doesn’t have and or care about dynamic data, Flux might not
be the best choice.
 Unidirectional data flow.
Thanh Tuong | ReactJS | 2016
36
ReactJS {Flux - flow}
Thanh Tuong | ReactJS | 2016
37
ReactJS {Flux - flow}
 Dispatcher
 Is the central hub that manages all data flow in a Flux application.
 Essentially a registry of callbacks into the stores.
Thanh Tuong | ReactJS | 2016
38
ReactJS {Flux - flow}
Dispatcher
Store Store Store Store
Thanh Tuong | ReactJS | 2016
39 When an action
creator provides
the dispatcher with
a new action, all
stores in the
application receive
the action via the
callbacks in the
registry.
Broadcast
ReactJS {Flux - flow}
 Stores
 Stores contain the application state and logic.
 Manage the state of many objects.
 Do not represent a single record of data like ORM models do.
 Store registers itself with the dispatcher and provides it with a callback.
Thanh Tuong | ReactJS | 2016
40
ReactJS {Flux - flow}
 Views
 Typical React component.
 After is mounted, it goes and get its initial state from Store and setup listener.
 When it receives the event from the store, it first requests the new data it needs
via the stores' public getter methods.
 Then, it calls its own setState() method, causing its render() method and the
render() method of all its descendants to run.
Thanh Tuong | ReactJS | 2016
41
ReactJS {Flux - flow}
Thanh Tuong | ReactJS | 2016
42
ReactJS {Flux - Implement}
 Flux is just an architect. So, you can design new framework by yourself base
on this architect.
 Many JavaScript libraries help you implement flux like:
 Flux (by Facebook: https://github.com/facebook/flux)
 Reflux(by Mikael Brassman: https://github.com/reflux/refluxjs)
 Redux(by Dan Abramov: https://github.com/reactjs/redux)
 …
Thanh Tuong | ReactJS | 2016
43
ReactJS {Flux – source code}
 https://github.com/tylermcginnis/Flux-Todolist
Thanh Tuong | ReactJS | 2016
44
ReactJS {contents}
 JSX
 Virtual-DOM
 Props
 PropTypes
 State
 Refs
 LifeCycle
 Flux Architech
 Routing
Thanh Tuong | ReactJS | 2016
45
ReactJS { thinking in… }
Thanh Tuong | ReactJS | 2016
46
How many
components
should I have?
How can I
break it?
ReactJS { thinking in… }
Thanh Tuong | ReactJS | 2016
47
1
4
2
2
3
3
5
5 FilterableProductTable: contains the entirety of the example
5 1 4SearchBar: receives all user input
4 ProductTable: displays and filters the data collection based on user input
2 ProductCategoryRow: displays a heading for each category
3 ProductRow: displays a row for each product
ReactJS { thinking in… }
Thanh Tuong | ReactJS | 2016
48
ReactJS {Routing}
 Make UI consistent with URL.
 https://github.com/reactjs/react-router/blob/latest/docs.
Thanh Tuong | ReactJS | 2016
49
ReactJS {references}
 http://tylermcginnis.com/reactjs-tutorial-a-comprehensive-guide-to-
building-apps-with-react/
 https://facebook.github.io/react/docs/getting-started.html
 https://github.com/reactjs/react-router/tree/latest/docs
 http://teropa.info/blog/2015/03/02/change-and-its-detection-in-javascript-
frameworks.html
 https://www.airpair.com/angularjs/posts/angular-vs-react-the-tie-breaker
Thanh Tuong | ReactJS | 2016
50
@ThanhTuong
SE at KMS technology
Thanh Tuong | ReactJS | 2016
51

More Related Content

What's hot (20)

Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Reactjs
Reactjs Reactjs
Reactjs
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
reactJS
reactJSreactJS
reactJS
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
React workshop
React workshopReact workshop
React workshop
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React JS
React JSReact JS
React JS
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
React js
React jsReact js
React js
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
 
React js
React jsReact js
React js
 
React state
React  stateReact  state
React state
 

Similar to ReactJS presentation

React mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Eheinovex GmbH
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and reduxCuong Ho
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSPratik Majumdar
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and SymfonyIgnacio Martín
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to ReactJean Carlo Emer
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...mfrancis
 
OSGi and Spring Data for simple (Web) Application Development
OSGi and Spring Data  for simple (Web) Application DevelopmentOSGi and Spring Data  for simple (Web) Application Development
OSGi and Spring Data for simple (Web) Application DevelopmentChristian Baranowski
 
Universal JS Applications with React
Universal JS Applications with ReactUniversal JS Applications with React
Universal JS Applications with ReactThanh Trần Trọng
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxCommit University
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with reactAmit Thakkar
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тягаVitebsk Miniq
 
React on Rails - RailsConf 2017 (Phoenix)
 React on Rails - RailsConf 2017 (Phoenix) React on Rails - RailsConf 2017 (Phoenix)
React on Rails - RailsConf 2017 (Phoenix)Jo Cranford
 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - Reactrbl002
 

Similar to ReactJS presentation (20)

React mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Ehe
 
Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
 
React
React React
React
 
ReactJS
ReactJSReactJS
ReactJS
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
 
RicoAjaxEngine
RicoAjaxEngineRicoAjaxEngine
RicoAjaxEngine
 
RicoAjaxEngine
RicoAjaxEngineRicoAjaxEngine
RicoAjaxEngine
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
OSGi and Spring Data for simple (Web) Application Development
OSGi and Spring Data  for simple (Web) Application DevelopmentOSGi and Spring Data  for simple (Web) Application Development
OSGi and Spring Data for simple (Web) Application Development
 
Universal JS Applications with React
Universal JS Applications with ReactUniversal JS Applications with React
Universal JS Applications with React
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with react
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
React on Rails - RailsConf 2017 (Phoenix)
 React on Rails - RailsConf 2017 (Phoenix) React on Rails - RailsConf 2017 (Phoenix)
React on Rails - RailsConf 2017 (Phoenix)
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
Ajax
AjaxAjax
Ajax
 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - React
 

Recently uploaded

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 

Recently uploaded (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

ReactJS presentation

  • 1. ReactJS The future of web development Thanh Tuong | ReactJS | 2016 1
  • 2. Thanh Tuong | ReactJS | 2016 2 https://github.com/facebook/react/wiki/Sites-Using-React
  • 3. History  In 2010, Facebook released an extension for PHP called XHP.  XHP help to decrease XSS attack and make front-end much both readable and understand. Thanh Tuong | ReactJS | 2016 <?php if ($_POST['name']) { echo <span>Hello, {$_POST['name']}</span>; } else { echo <form method="post"> What is your name?<br /> <input type="text" name="name" /> <input type="submit" /> </form>; } <?php if ($_POST['name']) { ?> <span>Hello, <?=$_POST['name']?>.</span> <?php } else { ?> <form method="post"> What is your name?<br> <input type="text" name="name"> <input type="submit"> </form> <?php } PHP XHP 3
  • 4. History (cont)  But…  There was a distinct problem with XHP: dynamic web applications require many roundtrips to the server.  XHP did not solve this problem.  A Facebook engineer negotiated with his manager to take XHP into the browser using JavaScript and was granted six months to try it.  And… Thanh Tuong | ReactJS | 2016 4 React was born
  • 5. ReactJS {purpose}  Creating user interface(V in MVC model).  Building large applications with data that changes over time. Thanh Tuong | ReactJS | 2016 5 var React = React.createClass({ render: function() { return ( <h1> Hello React </h1> ); } }); ReactDOM.render(<React />,document.getElementById('container')); Syntax
  • 6. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 6
  • 7. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 7
  • 8. ReactJS {JSX}  JSX is a JavaScript syntax extension that looks similar to XML.  Concise and familiar syntax for defining tree structures with attributes.  Make large trees easier to read than function calls or object literals.  Can be used in both HTML tags and Components. Thanh Tuong | ReactJS | 2016 8
  • 9. ReactJS {JSX – examples}  HTML tags  var myDivElement = <div className="foo" > HTML tags </div>;  ReactDOM.render(myDivElement, document.getElementById('example'));  Component  var MyComponent = React.createClass({/*...*/});  var myElement = <MyComponent />;  ReactDOM.render(myElement, document.getElementById('example')); Thanh Tuong | ReactJS | 2016 9
  • 10. ReactJS {JSX – examples (cont)}  HTML tags (without JSX)  var myDivElement = React.createElement('div', {className: 'foo'}, 'HTML tags');  ReactDOM.render(myDivElement, document.getElementById('example'));  Component (without JSX) var MyComponent = React.createClass({ render: function() { return ( React.createElement('h1',{}, 'Component without JSX') ); } }); var myElement = <MyComponent />; ReactDOM.render(myElement, document.getElementById('content')); Thanh Tuong | ReactJS | 2016 10
  • 11. ReactJS {JSX – Transform}  React JSX transforms from an XML-like syntax into native JavaScript.  XML elements, attributes and children are transformed into arguments that are passed to React.createElement. Thanh Tuong | ReactJS | 2016 11 Children
  • 12. ReactJS {JSX –Namespaced}  What if you are building a component with many children? For example Form.  Namespaced components help to make component simpler and easier.  You just need to create your "sub-components" as attributes of the main component. Thanh Tuong | ReactJS | 2016 12
  • 13. ReactJS {JSX –Namespaced (cont)} Thanh Tuong | ReactJS | 2016 13
  • 14. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 14
  • 15. ReactJS {Virtual-DOM}  Problem:  DOM manipulation is expensive.  Re-render all parts of DOM make your app slowly.  When the component’s state is changed, React will compare with DOM element to make smallest change.  Is made by React.createElement().  https://www.youtube.com/watch?v=BYbgopx44vo Thanh Tuong | ReactJS | 2016 15
  • 16. ReactJS {Virtual-DOM} Thanh Tuong | ReactJS | 2016 16 Only diff changes from the two V-DOMs are applied to real DOM
  • 17. ReactJS {Virtual-DOM (cont)}  1. Backbone.js recontruct DOM elements marked as “change”.  2. Backbone.js recontruct All DOM elements.  3. ReactJS recontruct DOM elements base on calculate the difference. Thanh Tuong | ReactJS | 2016 17
  • 18. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 18
  • 19. ReactJS {props}  Used to pass parameter from parent to children.  var HelloReact = React.createClass({ render: function() { return ( <h1> Hello, {this.props.name} </h1> ); } }); ReactDOM.render(<HelloReact name="ReactJS!!!" />, node); Thanh Tuong | ReactJS | 2016 19
  • 20. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 20
  • 21. ReactJS {PropTypes}  For validate the prop’s value input.  var HelloReact = React.createClass({ propTypes: { name: React.PropTypes.number }, render: function() { return ( <h1> Hello, {this.props.name} </h1> ); } }); ReactDOM.render(<HelloReact name="thanh" />, document.getElementById('content')); Thanh Tuong | ReactJS | 2016 21
  • 22. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 22
  • 23. ReactJS {state}  To manage state inside component.  getInitialState() function: init value for variable.  setState() function: update new value for variable. Thanh Tuong | ReactJS | 2016 23
  • 24. ReactJS {state-(cont)}  When you should use state?  Respond to user input.  Server request.  or the passage of time. Thanh Tuong | ReactJS | 2016 24
  • 25. ReactJS { props vs state } Features props state Can get initial value from parent Component? Yes Yes Can be changed by parent Component? Yes No Can set default values inside Component? Yes Yes Can change inside Component? No Yes Can set initial value for child Components? Yes Yes Can change in child Components? Yes No Thanh Tuong | ReactJS | 2016 25
  • 26. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 26
  • 27. ReactJS {refs}  How we make focus to input element after clear data from input element?  How we can make a search with many criteria ?  … Thanh Tuong | ReactJS | 2016 27 Refs
  • 28. ReactJS {refs-(cont)} Thanh Tuong | ReactJS | 2016 28 Type… Click clear
  • 29. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 29
  • 30. ReactJS {LifeCycle}  Each component has its own lifecycle events.  Ex:  If we wanted to make an ajax request on the initial render and fetch some data, where would we do that?  If we wanted to run some logic whenever our props changed, how would we do that?  … Thanh Tuong | ReactJS | 2016 30 LifeCycle events
  • 31. ReactJS {LifeCycle (cont)}  componentWillMount  Invoked once (both on the client and server ) before the initial render.  Good place to make connection to your db service (ex: firebase,...)  Do not call set state method here. Thanh Tuong | ReactJS | 2016 31
  • 32. ReactJS {LifeCycle (cont)}  componentDidMount  Invoked once, only on the client (not on the server).  Immediately after the initial rendering occurs.  It is good place for you to make AJAX request to fetch data for first used. Thanh Tuong | ReactJS | 2016 32
  • 33. ReactJS {LifeCycle (cont)}  componentWillReceiveProps  Invoked when a component is receiving new props.  This method is not called for the initial render.  Use this method as a way to react to a prop change before render() is called by updating the state with setState. Thanh Tuong | ReactJS | 2016 33
  • 34. ReactJS {LifeCycle (cont)}  componentWillUnmount  Invoked immediately before a component is unmounted from the DOM.  Perform any necessary cleanup in this method(Ex: invalidating timers, clear up DOM elements were created at componentDidMount) Thanh Tuong | ReactJS | 2016 34 Nothing!!! http://facebook.github.io/react/docs/component- specs.html
  • 35. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Thinking in React  Routing Thanh Tuong | ReactJS | 2016 35
  • 36. ReactJS {Flux}  Flux is the application architecture.  Making data changes easy.  Remove the burden of having a component manage its own state.  The data is moved to the central called Store.  If your app doesn’t have and or care about dynamic data, Flux might not be the best choice.  Unidirectional data flow. Thanh Tuong | ReactJS | 2016 36
  • 37. ReactJS {Flux - flow} Thanh Tuong | ReactJS | 2016 37
  • 38. ReactJS {Flux - flow}  Dispatcher  Is the central hub that manages all data flow in a Flux application.  Essentially a registry of callbacks into the stores. Thanh Tuong | ReactJS | 2016 38
  • 39. ReactJS {Flux - flow} Dispatcher Store Store Store Store Thanh Tuong | ReactJS | 2016 39 When an action creator provides the dispatcher with a new action, all stores in the application receive the action via the callbacks in the registry. Broadcast
  • 40. ReactJS {Flux - flow}  Stores  Stores contain the application state and logic.  Manage the state of many objects.  Do not represent a single record of data like ORM models do.  Store registers itself with the dispatcher and provides it with a callback. Thanh Tuong | ReactJS | 2016 40
  • 41. ReactJS {Flux - flow}  Views  Typical React component.  After is mounted, it goes and get its initial state from Store and setup listener.  When it receives the event from the store, it first requests the new data it needs via the stores' public getter methods.  Then, it calls its own setState() method, causing its render() method and the render() method of all its descendants to run. Thanh Tuong | ReactJS | 2016 41
  • 42. ReactJS {Flux - flow} Thanh Tuong | ReactJS | 2016 42
  • 43. ReactJS {Flux - Implement}  Flux is just an architect. So, you can design new framework by yourself base on this architect.  Many JavaScript libraries help you implement flux like:  Flux (by Facebook: https://github.com/facebook/flux)  Reflux(by Mikael Brassman: https://github.com/reflux/refluxjs)  Redux(by Dan Abramov: https://github.com/reactjs/redux)  … Thanh Tuong | ReactJS | 2016 43
  • 44. ReactJS {Flux – source code}  https://github.com/tylermcginnis/Flux-Todolist Thanh Tuong | ReactJS | 2016 44
  • 45. ReactJS {contents}  JSX  Virtual-DOM  Props  PropTypes  State  Refs  LifeCycle  Flux Architech  Routing Thanh Tuong | ReactJS | 2016 45
  • 46. ReactJS { thinking in… } Thanh Tuong | ReactJS | 2016 46 How many components should I have? How can I break it?
  • 47. ReactJS { thinking in… } Thanh Tuong | ReactJS | 2016 47 1 4 2 2 3 3 5 5 FilterableProductTable: contains the entirety of the example 5 1 4SearchBar: receives all user input 4 ProductTable: displays and filters the data collection based on user input 2 ProductCategoryRow: displays a heading for each category 3 ProductRow: displays a row for each product
  • 48. ReactJS { thinking in… } Thanh Tuong | ReactJS | 2016 48
  • 49. ReactJS {Routing}  Make UI consistent with URL.  https://github.com/reactjs/react-router/blob/latest/docs. Thanh Tuong | ReactJS | 2016 49
  • 50. ReactJS {references}  http://tylermcginnis.com/reactjs-tutorial-a-comprehensive-guide-to- building-apps-with-react/  https://facebook.github.io/react/docs/getting-started.html  https://github.com/reactjs/react-router/tree/latest/docs  http://teropa.info/blog/2015/03/02/change-and-its-detection-in-javascript- frameworks.html  https://www.airpair.com/angularjs/posts/angular-vs-react-the-tie-breaker Thanh Tuong | ReactJS | 2016 50
  • 51. @ThanhTuong SE at KMS technology Thanh Tuong | ReactJS | 2016 51