SlideShare a Scribd company logo
REACTA PRESENTATION FOR OTTAWAJS
Hello
@brucelefebvre
REACT:
A JAVASCRIPT LIBRARY FOR CREATING
USER INTERFACES
Why React?
Component based
Fast
Performance
To learn
Simple
No templates
Means no abstractions
Markup lives with its corresponding view logic
Demo!
On the Shoulders of Giants
React - http://facebook.github.io/react/
React Router - https://rackt.github.io/react-router/
React Intl - http://formatjs.io/react/
Ionic Framework CSS - http://ionicframework.com/
Firebase - https://www.firebase.com/
PhoneGap - http://phonegap.com/
Dashboard Components
Dashboard Components
Dashboard
Header
EventSelector
EventTypeLink
EventHistory
Event
DiaperEvent
FormattedRelative
OttawaJS - React
AddDiaperEvent
Header
DiaperEventForm
TimeSelector
...with React, the only
thing you do is build
components.
- Why React?
Your First Component
var Header = React.createClass({
render: function() {
return (
<h1>{this.props.title}</h1>
);
}
});
Use It
var Header = React.createClass({
render: function() {
return (
<h1>{this.props.title}</h1>
);
}
});
React.render(
<Header title="Poop Monitor" />,
document.getElementById('app')
);
Component Basics
Component output is simply a function of
`state` and `props`
Data flows from "Owner to Owned"
<Parent><Child /></Parent>
Declarative
Focus is on _what_ the program should
accomplish without prescribing how to do it
A Stateful Component
var EventHistory = React.createClass({
getInitialState: function() {
return {events: []};
},
componentWillMount: function() {
var eventItems = [];
this.dataProvider = new PMDataProvider();
this.dataProvider.getEvents(function(event) {
// `unshift` used instead of `push` to place the newest items at the top
eventItems.unshift(event);
this.setState({
events: eventItems
});
}.bind(this));
},
componentWillUnmount: function() {
this.dataProvider.close();
},
render: function() {
var eventNodes = this.state.events.map(function (event, keyIndex) {
var eventComponent;
if (event.type === "Diaper") {
return (<DiaperEvent event={event} key={keyIndex} />);
}
else {
return (<Event event={event} key={keyIndex} />);
}
});
return (
<div className="list card">
{eventNodes}
</div>
);
}
});
Let's Break it Down
var EventHistory = React.createClass({
getInitialState: function() {
// Set up the component's initial state
},
componentWillMount: function() {
// Component is about to be rendered
},
componentWillUnmount: function() {
// Component is about to be removed from the DOM
},
render: function() {
// Returns a single child element
// Pure:
// - Does not modify state
// - Does not interact with the DOM directly
// - Returns same result each time it is invoked
}
});
More on component lifecycle methods can be found here
...code is read far more
than it's written, and it's
extremely easy to read
this modular, explicit
code.
- Pete Hunt, Thinking in React
Speed: at a price
No two-way data binding; `props` flow from parent to child
Form element data often needs to propogate up
var GenericEventForm = React.createClass({
onDateUpdate: function(date) {
// Deal with the updated date
},
render: function() {
return (
<form className="eventForm">
<TimeSelector onUpdate={this.onDateUpdate}/>
</form>
)
}
});
var TimeSelector = React.createClass({
timeSelectionChanged: function(e) {
var eventDate = new Date(); // manipulate date as required
this.props.onUpdate(eventDate);
},
render: function() {
// Simplified for code sample
return (
<input type="radio" name="timeOption" onChange={this.timeSelectionChanged} />
);
}
});
Gotchas
Use an NPM/Gulp/Browserify workflow from the start
Like this react-app-boilerplate
Beware copying source from non-React samples
`class` becomes `className`
`for` becomes `htmlFor`
React is not a monolithic framework like Angular
It will not make XHRs for you
It does not handle routing between views
You will have to code your own page transitions
Thanks!
Project source on Github: bit.ly/ott-react

More Related Content

PDF
An Overview of the React Ecosystem
PDF
Rest web service_with_spring_hateoas
PDF
Introduce Flux & react in practices (KKBOX)
PDF
Ryan Christiani I Heard React Was Good
PPTX
React and Flux life cycle with JSX, React Router and Jest Unit Testing
PPTX
Dependency Inversion in large-scale TypeScript applications with InversifyJS
PDF
Redux Universal
PPTX
React - Start learning today
An Overview of the React Ecosystem
Rest web service_with_spring_hateoas
Introduce Flux & react in practices (KKBOX)
Ryan Christiani I Heard React Was Good
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Dependency Inversion in large-scale TypeScript applications with InversifyJS
Redux Universal
React - Start learning today

What's hot (20)

PDF
React Native +Redux + ES6 (Updated)
PDF
Workshop React.js
PDF
Building a Single Page App: One Page at a Time
PDF
Railsconf 2017 - React & React Native a common codebase across native and web
PDF
React on es6+
PPTX
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
PPTX
Intro to Flux - ReactJS Warsaw #1
PPTX
Building high-performance web applications with Preact
PDF
React on Rails - RailsConf 2017 (Phoenix)
PPTX
7 Redux challenges
PDF
React and redux
PDF
Introduction to ReactJS
PPTX
Rethinking Best Practices
PDF
Redux and context api with react native app introduction, use cases, implemen...
PDF
React for Dummies
PPTX
Top 10 RxJs Operators in Angular
PDF
using Mithril.js + postgREST to build and consume API's
PPTX
PostgREST Design Philosophy
PPTX
Flux and React.js
React Native +Redux + ES6 (Updated)
Workshop React.js
Building a Single Page App: One Page at a Time
Railsconf 2017 - React & React Native a common codebase across native and web
React on es6+
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Intro to Flux - ReactJS Warsaw #1
Building high-performance web applications with Preact
React on Rails - RailsConf 2017 (Phoenix)
7 Redux challenges
React and redux
Introduction to ReactJS
Rethinking Best Practices
Redux and context api with react native app introduction, use cases, implemen...
React for Dummies
Top 10 RxJs Operators in Angular
using Mithril.js + postgREST to build and consume API's
PostgREST Design Philosophy
Flux and React.js
Ad

Similar to OttawaJS - React (20)

PPTX
PPTX
Adding a modern twist to legacy web applications
PPTX
Intro react js
PDF
Corso su ReactJS
PDF
Full Stack React Workshop [CSSC x GDSC]
PDF
Fundamental concepts of react js
PDF
React & The Art of Managing Complexity
PDF
A full introductory guide to React
PDF
A React Journey
PDF
Enhance react app with patterns - part 1: higher order component
PPTX
Adding a modern twist to legacy web applications
PDF
Content-Driven Apps with React
PDF
The Exciting Future Of React
PDF
React js
PPTX
Let's react - Meetup
PPTX
ReactJS (1)
PDF
Introduction to react
PPTX
react-slides.pptx
PDF
React Native for multi-platform mobile applications
PPTX
React, Flux and more (p1)
Adding a modern twist to legacy web applications
Intro react js
Corso su ReactJS
Full Stack React Workshop [CSSC x GDSC]
Fundamental concepts of react js
React & The Art of Managing Complexity
A full introductory guide to React
A React Journey
Enhance react app with patterns - part 1: higher order component
Adding a modern twist to legacy web applications
Content-Driven Apps with React
The Exciting Future Of React
React js
Let's react - Meetup
ReactJS (1)
Introduction to react
react-slides.pptx
React Native for multi-platform mobile applications
React, Flux and more (p1)
Ad

Recently uploaded (20)

PPTX
Online Work Permit System for Fast Permit Processing
PDF
medical staffing services at VALiNTRY
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Nekopoi APK 2025 free lastest update
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
Online Work Permit System for Fast Permit Processing
medical staffing services at VALiNTRY
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Introduction to Artificial Intelligence
Design an Analysis of Algorithms I-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ISO 45001 Occupational Health and Safety Management System
Odoo Companies in India – Driving Business Transformation.pdf
ai tools demonstartion for schools and inter college
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Navsoft: AI-Powered Business Solutions & Custom Software Development
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Nekopoi APK 2025 free lastest update
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How to Choose the Right IT Partner for Your Business in Malaysia

OttawaJS - React

  • 3. REACT: A JAVASCRIPT LIBRARY FOR CREATING USER INTERFACES
  • 4. Why React? Component based Fast Performance To learn Simple No templates Means no abstractions Markup lives with its corresponding view logic
  • 6. On the Shoulders of Giants React - http://facebook.github.io/react/ React Router - https://rackt.github.io/react-router/ React Intl - http://formatjs.io/react/ Ionic Framework CSS - http://ionicframework.com/ Firebase - https://www.firebase.com/ PhoneGap - http://phonegap.com/
  • 11. ...with React, the only thing you do is build components. - Why React?
  • 12. Your First Component var Header = React.createClass({ render: function() { return ( <h1>{this.props.title}</h1> ); } });
  • 13. Use It var Header = React.createClass({ render: function() { return ( <h1>{this.props.title}</h1> ); } }); React.render( <Header title="Poop Monitor" />, document.getElementById('app') );
  • 14. Component Basics Component output is simply a function of `state` and `props` Data flows from "Owner to Owned" <Parent><Child /></Parent> Declarative Focus is on _what_ the program should accomplish without prescribing how to do it
  • 15. A Stateful Component var EventHistory = React.createClass({ getInitialState: function() { return {events: []}; }, componentWillMount: function() { var eventItems = []; this.dataProvider = new PMDataProvider(); this.dataProvider.getEvents(function(event) { // `unshift` used instead of `push` to place the newest items at the top eventItems.unshift(event); this.setState({ events: eventItems }); }.bind(this)); }, componentWillUnmount: function() { this.dataProvider.close(); }, render: function() { var eventNodes = this.state.events.map(function (event, keyIndex) { var eventComponent; if (event.type === "Diaper") { return (<DiaperEvent event={event} key={keyIndex} />); } else { return (<Event event={event} key={keyIndex} />); } }); return ( <div className="list card"> {eventNodes} </div> ); } });
  • 16. Let's Break it Down var EventHistory = React.createClass({ getInitialState: function() { // Set up the component's initial state }, componentWillMount: function() { // Component is about to be rendered }, componentWillUnmount: function() { // Component is about to be removed from the DOM }, render: function() { // Returns a single child element // Pure: // - Does not modify state // - Does not interact with the DOM directly // - Returns same result each time it is invoked } }); More on component lifecycle methods can be found here
  • 17. ...code is read far more than it's written, and it's extremely easy to read this modular, explicit code. - Pete Hunt, Thinking in React
  • 18. Speed: at a price No two-way data binding; `props` flow from parent to child Form element data often needs to propogate up var GenericEventForm = React.createClass({ onDateUpdate: function(date) { // Deal with the updated date }, render: function() { return ( <form className="eventForm"> <TimeSelector onUpdate={this.onDateUpdate}/> </form> ) } }); var TimeSelector = React.createClass({ timeSelectionChanged: function(e) { var eventDate = new Date(); // manipulate date as required this.props.onUpdate(eventDate); }, render: function() { // Simplified for code sample return ( <input type="radio" name="timeOption" onChange={this.timeSelectionChanged} /> ); } });
  • 19. Gotchas Use an NPM/Gulp/Browserify workflow from the start Like this react-app-boilerplate Beware copying source from non-React samples `class` becomes `className` `for` becomes `htmlFor` React is not a monolithic framework like Angular It will not make XHRs for you It does not handle routing between views You will have to code your own page transitions
  • 21. Project source on Github: bit.ly/ott-react