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
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

What's hot

React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
Chiew Carol
 
Workshop React.js
Workshop React.jsWorkshop React.js
Workshop React.js
Commit University
 
Building a Single Page App: One Page at a Time
Building a Single Page App: One Page at a TimeBuilding a Single Page App: One Page at a Time
Building a Single Page App: One Page at a Time
Ivayr Farah Netto
 
Railsconf 2017 - React & React Native a common codebase across native and web
Railsconf 2017 - React & React Native a common codebase across native and webRailsconf 2017 - React & React Native a common codebase across native and web
Railsconf 2017 - React & React Native a common codebase across native and web
talkingquickly
 
React on es6+
React on es6+React on es6+
React on es6+
Nikolaus Graf
 
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
React vs Angular: ups & downs (speaker Oleksandr Kovalov, Binary Studio)
Binary Studio
 
Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1Intro to Flux - ReactJS Warsaw #1
Intro to Flux - ReactJS Warsaw #1
Damian Legawiec
 
Building high-performance web applications with Preact
Building high-performance web applications with PreactBuilding high-performance web applications with Preact
Building high-performance web applications with Preact
Maurice De Beijer [MVP]
 
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
 
7 Redux challenges
7 Redux challenges7 Redux challenges
7 Redux challenges
reactima
 
React and redux
React and reduxReact and redux
React and redux
Mystic Coders, LLC
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Tu Hoang
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
floydophone
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
Katy Slemon
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
Mitch Chen
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
Jalpesh Vadgama
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
PostgREST Design Philosophy
PostgREST Design PhilosophyPostgREST Design Philosophy
PostgREST Design Philosophy
begriffs
 
Flux and React.js
Flux and React.jsFlux and React.js
Flux and React.js
sara stanford
 

What's hot (20)

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

Similar to OttawaJS - React

ReactJS
ReactJSReactJS
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
LinkMe Srl
 
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
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
React & The Art of Managing Complexity
React &  The Art of Managing ComplexityReact &  The Art of Managing Complexity
React & The Art of Managing Complexity
Ryan Anklam
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
Jean Carlo Emer
 
A React Journey
A React JourneyA React Journey
A React Journey
LinkMe Srl
 
Enhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order component
Yao Nien Chung
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
Netcetera
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of React
kristijanmkd
 
React js
React jsReact js
React js
Rajesh Kolla
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
RAJNISH KATHAROTIYA
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
kiranabburi
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
DayNightGaMiNg
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
Matteo Manchi
 
React, Flux and more (p1)
React, Flux and more (p1)React, Flux and more (p1)
React, Flux and more (p1)
tuanpa206
 

Similar to OttawaJS - React (20)

ReactJS
ReactJSReactJS
ReactJS
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
 
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]
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React & The Art of Managing Complexity
React &  The Art of Managing ComplexityReact &  The Art of Managing Complexity
React & The Art of Managing Complexity
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
 
A React Journey
A React JourneyA React Journey
A React Journey
 
Enhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order component
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of React
 
React js
React jsReact js
React js
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
ReactJS (1)
ReactJS (1)ReactJS (1)
ReactJS (1)
 
Introduction to react
Introduction to reactIntroduction to react
Introduction to react
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
React, Flux and more (p1)
React, Flux and more (p1)React, Flux and more (p1)
React, Flux and more (p1)
 

Recently uploaded

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

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/
  • 9.
  • 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