SlideShare a Scribd company logo
Up & Running
with ReactJS
June 9, 2015 @ PeopleSpace
Education, tech startups, community
peoplespace.us
Up and Running with ReactJS
Up and Running with ReactJS
React.render(<Selfie/>)
● Freelancer building web and mobile UIs
● AngularJS-OC organizer too
● Node, Ruby, Java, C# too
● locnguyen.com, @locn
Goals
● Learn React building blocks
● See how the component APIs work
● Go home knowing how to start using React
Agenda
1. Origins
2. React components
3. Component state and props
4. Component refs and events
5. React Router
About React
● Originated at FB and Instagram
● A declarative view library, the “V” in MVC
● Improves web dev experience with simple,
cohesive component model
● React - Rethinking Best Practices
Who’s using it?
● Facebook, Instagram (duh)
● AirBnB
● Netflix
● Atlassian (HipChat)
● Yahoo (Mail)
Hello World
var Hello = React.createClass({
render: function () {
return <div>Hello World</div>;
}
});
React.renderComponent(<Hello/>, document.body);
React Components
● Fundamental building block of React
● Maps to elements in your DOM
● Composable units to structure your app
● Like directives in AngularJS
High cohesion
● Encapsulates display logic and view
JSX
render() {
return (
<nav className="top-nav">
<ul className"horizontal-link-list">
{links.map(function (link) {
return (
<li key={link.id}
className={loggedIn ? 'warn' : ''}>
<a href={link.href}>{link.text}</a>
</li>
);
})}
</ul>
</nav>
);
}
render() {
return (
<nav className="top-nav">
<ul className"horizontal-link-list">
{links.map(function (link) {
return (
<li key={link.id}>
<a href={link.href}>{link.text}</a>
</li>
);
})}
</ul>
</nav>
);
}
JSX (it’s a feature, not a bug)
● Preprocessor that only looks like HTML
● NOT strings of markup w/XSS vulnerability
● Sugar for calling React functions
● No need for abstractions in a template lang
<ng-if> or {{#if}}
JSX
JavaScript
React.createClass({
render: function () {
return (
<ul id="tasks">
<li>Task 1</li>
</ul>
);
}
});
var li = React.createElement('li',
null, 'Task 1');
var ul = React.createElement('ul',
{id:'tasks'}, li);
React.render(ul, document.body);
Data binding
● Key-value observation: EmberJS,
KnockoutJS
● Dirty checking: AngularJS
● State is hard, so UIs are hard
● “Refreshing” the page is easy
The virtual DOM
● React’s (Simple) Secret Sauce
● In-memory representation of the DOM
● Diffs changes and updates DOM as needed
● Be Predictable, Not Correct
The render function
● Insert JSX here
● Called when component is mounted
● Called every time the state changes
● “refresh” the page except mutate DOM only
where needed
Component properties
● For data that does not change
● Props are just attributes assigned in JSX
● Accessible with this.props
● getDefaultProps() - set default values if
not provided
Property Example
var Meetup = React.createClass({
render: function () {
return <h1>{this.props.name}</h1>;
}
});
React.render(<Meetup name="ReactJS OC" />,
document.body);
Component state
● For data that changes
● Accessible with this.state
● getInitialState() - sets the initial state
values
● this.setState()calls render()!
Live: state example
Credit to Ryan Florence
Refs
● Get a handle to your actual DOM elements
● <input type="text" ref="email" />
● this.refs.email
● Interact with DOM APIs
Event handlers
● Add to your elements inline
this.poke = function () { alert('howdy'); }
<button onClick={this.poke}>Poke</button>
● Send arguments with .bind
<button onClick={this.poke.bind(null,
'Loc')}>Poke</button>
Live: refs & events example
Simple Routing
● Just switch between components
var Dashboard = React.createClass(...);
var Home = React.createClass(...);
Simple Routing
● Just switch between components
var Dashboard = React.createClass(...);
var Home = React.createClass(...);
Simple Routing (cont’d)
var App = React.createClass({
render: function () {
var Child;
switch (this.props.route) {
case 'dashboard': Child = Dashboard; break;
case 'home': Child = Home; break;
default: Child = Home;
}
return <div><Child/></div>;
}
});
Simple Routing (cont’d)
function render () {
var route = window.location.hash.substr(1);
React.render(<App route={route} />, document.body);
}
window.addEventListener('hashchange', render);
render(); // render initially
React Router
● Routing library by Ryan Florence
● Heavily influence by Ember Router
● Makes nested states simple
● GitHub, Examples, Docs
Routes Declaration
<Route handler={App} path="/">
<Route name="home" path="home" handler={Home} />
<Route name="dashboard" path="dashboard"
handler={Dashboard}/>
</Route>
Links
<Link to="home">Home</Link>
<Link to="dashboard">Dashboard</Link>
Live: React Router Example
Free Resources
● The docs
● ReactConf 2015 Videos
● The Secrets of React’s Virtual DOM
● React Podcast
Paid Resources
● egghead.io - React, Native, Flux
● frontendmasters.com - 4.5 hour React intro
● pluralsight.com - 3 hour React intro
● reactweek.com - React, Flux, Router,
Webpack
What’s next? Need speakers!
● Component lifecycle
● Component best practices
● 3rd party JS integration
● React Router
● Data flow, Flux architecture
● React Native
● Testing
● Tooling
Up and Running with ReactJS

More Related Content

What's hot (20)

Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
Harvard Web Working Group
 
AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
Glib Kechyn
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
Mitch Chen
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
Ali Sa'o
 
React.js+Redux Workshops
React.js+Redux WorkshopsReact.js+Redux Workshops
React.js+Redux Workshops
Marcin Grzywaczewski
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
Vinícius Ribeiro
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
Sergey Romaneko
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
Vedran Blaženka
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
kiranabburi
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016
Simon Sturmer
 
React.js
React.jsReact.js
React.js
Łukasz Kużyński
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
Caldera Labs
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
All Things Open
 
AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
Glib Kechyn
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
Mitch Chen
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
Ali Sa'o
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
Vedran Blaženka
 
REACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScriptREACT.JS : Rethinking UI Development Using JavaScript
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
kiranabburi
 
React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016React Fundamentals - Jakarta JS, Apr 2016
React Fundamentals - Jakarta JS, Apr 2016
Simon Sturmer
 
Introduction to AJAX In WordPress
Introduction to AJAX In WordPressIntroduction to AJAX In WordPress
Introduction to AJAX In WordPress
Caldera Labs
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
All Things Open
 

Similar to Up and Running with ReactJS (20)

React js
React jsReact js
React js
Rajesh Kolla
 
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
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
Zach Lendon
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Zach Lendon
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
Ritesh Kumar
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
react js training|react js training in mumbai|React js classes in mumbai
react js training|react js training in mumbai|React js classes in mumbaireact js training|react js training in mumbai|React js classes in mumbai
react js training|react js training in mumbai|React js classes in mumbai
EsgbnmkPhcm
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
Atlogys Technical Consulting
 
ReactJs
ReactJsReactJs
ReactJs
Sahana Banerjee
 
reactJS
reactJSreactJS
reactJS
Syam Santhosh
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
Why react is different
Why react is differentWhy react is different
Why react is different
JakeGinnivan
 
ReactJS (1)
ReactJS (1)ReactJS (1)
ReactJS (1)
George Tony
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfgNEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio Martín
 
React, Flux and a little bit of Redux
React, Flux and a little bit of ReduxReact, Flux and a little bit of Redux
React, Flux and a little bit of Redux
Ny Fanilo Andrianjafy, B.Eng.
 
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
Ignacio Martín
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
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
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
Zach Lendon
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Zach Lendon
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
Ritesh Kumar
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 
react js training|react js training in mumbai|React js classes in mumbai
react js training|react js training in mumbai|React js classes in mumbaireact js training|react js training in mumbai|React js classes in mumbai
react js training|react js training in mumbai|React js classes in mumbai
EsgbnmkPhcm
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
Why react is different
Why react is differentWhy react is different
Why react is different
JakeGinnivan
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfgNEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
Ignacio Martín
 
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
Ignacio Martín
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
Ad

Recently uploaded (20)

Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
Influence line diagram in a robust model
Influence line diagram in a robust modelInfluence line diagram in a robust model
Influence line diagram in a robust model
ParthaSengupta26
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
UNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and ControlUNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and Control
Sridhar191373
 
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
ManiMaran230751
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdfKevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Kevin Corke Spouse Revealed A Deep Dive Into His Private Life.pdf
Medicoz Clinic
 
Structural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptxStructural Health and Factors affecting.pptx
Structural Health and Factors affecting.pptx
gunjalsachin
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
Influence line diagram in a robust model
Influence line diagram in a robust modelInfluence line diagram in a robust model
Influence line diagram in a robust model
ParthaSengupta26
 
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
May 2025: Top 10 Cited Articles in Software Engineering & Applications Intern...
sebastianku31
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDINGMODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
MODULE 5 BUILDING PLANNING AND DESIGN SY BTECH ACOUSTICS SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
UNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and ControlUNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and Control
Sridhar191373
 
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
ManiMaran230751
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
Ad

Up and Running with ReactJS

  • 1. Up & Running with ReactJS June 9, 2015 @ PeopleSpace
  • 2. Education, tech startups, community peoplespace.us
  • 5. React.render(<Selfie/>) ● Freelancer building web and mobile UIs ● AngularJS-OC organizer too ● Node, Ruby, Java, C# too ● locnguyen.com, @locn
  • 6. Goals ● Learn React building blocks ● See how the component APIs work ● Go home knowing how to start using React
  • 7. Agenda 1. Origins 2. React components 3. Component state and props 4. Component refs and events 5. React Router
  • 8. About React ● Originated at FB and Instagram ● A declarative view library, the “V” in MVC ● Improves web dev experience with simple, cohesive component model ● React - Rethinking Best Practices
  • 9. Who’s using it? ● Facebook, Instagram (duh) ● AirBnB ● Netflix ● Atlassian (HipChat) ● Yahoo (Mail)
  • 10. Hello World var Hello = React.createClass({ render: function () { return <div>Hello World</div>; } }); React.renderComponent(<Hello/>, document.body);
  • 11. React Components ● Fundamental building block of React ● Maps to elements in your DOM ● Composable units to structure your app ● Like directives in AngularJS
  • 12. High cohesion ● Encapsulates display logic and view
  • 13. JSX
  • 14. render() { return ( <nav className="top-nav"> <ul className"horizontal-link-list"> {links.map(function (link) { return ( <li key={link.id} className={loggedIn ? 'warn' : ''}> <a href={link.href}>{link.text}</a> </li> ); })} </ul> </nav> ); }
  • 15. render() { return ( <nav className="top-nav"> <ul className"horizontal-link-list"> {links.map(function (link) { return ( <li key={link.id}> <a href={link.href}>{link.text}</a> </li> ); })} </ul> </nav> ); }
  • 16. JSX (it’s a feature, not a bug) ● Preprocessor that only looks like HTML ● NOT strings of markup w/XSS vulnerability ● Sugar for calling React functions ● No need for abstractions in a template lang <ng-if> or {{#if}}
  • 17. JSX JavaScript React.createClass({ render: function () { return ( <ul id="tasks"> <li>Task 1</li> </ul> ); } }); var li = React.createElement('li', null, 'Task 1'); var ul = React.createElement('ul', {id:'tasks'}, li); React.render(ul, document.body);
  • 18. Data binding ● Key-value observation: EmberJS, KnockoutJS ● Dirty checking: AngularJS ● State is hard, so UIs are hard ● “Refreshing” the page is easy
  • 19. The virtual DOM ● React’s (Simple) Secret Sauce ● In-memory representation of the DOM ● Diffs changes and updates DOM as needed ● Be Predictable, Not Correct
  • 20. The render function ● Insert JSX here ● Called when component is mounted ● Called every time the state changes ● “refresh” the page except mutate DOM only where needed
  • 21. Component properties ● For data that does not change ● Props are just attributes assigned in JSX ● Accessible with this.props ● getDefaultProps() - set default values if not provided
  • 22. Property Example var Meetup = React.createClass({ render: function () { return <h1>{this.props.name}</h1>; } }); React.render(<Meetup name="ReactJS OC" />, document.body);
  • 23. Component state ● For data that changes ● Accessible with this.state ● getInitialState() - sets the initial state values ● this.setState()calls render()!
  • 25. Credit to Ryan Florence
  • 26. Refs ● Get a handle to your actual DOM elements ● <input type="text" ref="email" /> ● this.refs.email ● Interact with DOM APIs
  • 27. Event handlers ● Add to your elements inline this.poke = function () { alert('howdy'); } <button onClick={this.poke}>Poke</button> ● Send arguments with .bind <button onClick={this.poke.bind(null, 'Loc')}>Poke</button>
  • 28. Live: refs & events example
  • 29. Simple Routing ● Just switch between components var Dashboard = React.createClass(...); var Home = React.createClass(...);
  • 30. Simple Routing ● Just switch between components var Dashboard = React.createClass(...); var Home = React.createClass(...);
  • 31. Simple Routing (cont’d) var App = React.createClass({ render: function () { var Child; switch (this.props.route) { case 'dashboard': Child = Dashboard; break; case 'home': Child = Home; break; default: Child = Home; } return <div><Child/></div>; } });
  • 32. Simple Routing (cont’d) function render () { var route = window.location.hash.substr(1); React.render(<App route={route} />, document.body); } window.addEventListener('hashchange', render); render(); // render initially
  • 33. React Router ● Routing library by Ryan Florence ● Heavily influence by Ember Router ● Makes nested states simple ● GitHub, Examples, Docs
  • 34. Routes Declaration <Route handler={App} path="/"> <Route name="home" path="home" handler={Home} /> <Route name="dashboard" path="dashboard" handler={Dashboard}/> </Route>
  • 37. Free Resources ● The docs ● ReactConf 2015 Videos ● The Secrets of React’s Virtual DOM ● React Podcast
  • 38. Paid Resources ● egghead.io - React, Native, Flux ● frontendmasters.com - 4.5 hour React intro ● pluralsight.com - 3 hour React intro ● reactweek.com - React, Flux, Router, Webpack
  • 39. What’s next? Need speakers! ● Component lifecycle ● Component best practices ● 3rd party JS integration ● React Router ● Data flow, Flux architecture ● React Native ● Testing ● Tooling