SlideShare a Scribd company logo
July 5, 2015
Ilia Lobsanov
A gentle introduction
Objectives
• Build a user interface by diving into code
• Learn the basics of React
What’s React?
• A javascript library for building user interfaces
• Great for single-page applications
• Developed at Facebook/Instagram, open-sourced in
2013
• Used by Khan Academy, New York Times, Airbnb
The Basics
1 var HelloMessage = React.createClass({
2 render: function() {
3 return <div>Hello {this.props.name}</div>;
4 }
5 });
6
7 React.render(<HelloMessage name="John" />, mountNode);
The Basics
1 var HelloMessage = React.createClass({
2 render: function() {
3 return <div>Hello {this.props.name}</div>;
4 }
5 });
6
7 React.render(<HelloMessage name="John" />, mountNode);
The Interface
The Interface
FriendForm
FriendList
Friend
FriendBox
1 var Friend = React.createClass({
2 render: function() {
3 return (
4 <div className="friend">
5 <h2 className="name">
6 {this.props.name}
7 </h2>
8 </div>
9 );
10 }
11 });
1 var FriendList = React.createClass({
2 render: function() {
3 var friendNodes = this.props.data.map(function(friend) {
4 return (
5 <Friend name={friend.name}>
6 </Friend>
7 );
8 });
9
10 return (
11 <div className="friendList">
12 {friendNodes}
13 </div>
14 );
15 }
16 });
1 var FriendForm = React.createClass({
2 handleChange: function(e) {
3 e.preventDefault();
4 var name = React.findDOMNode(this.refs.name).value.trim();
5
6 this.props.onFriendChange({
7 name: name
8 });
9 },
10
11 render: function() {
12 return (
13 <form className="friendForm">
14 Name:
15 <input type="text" ref="name" onChange={this.handleChange}/>
16 </form>
17 );
18 }
19 });
1 var FriendBox = React.createClass({
2 loadFriendsFromServer: function(formData) {
3 $.get(this.props.url, formData, function(data) {
4 this.setState({ data: data.friends });
5 }.bind(this));
6 },
7
8 render: function() {
9 return (
10 <div className="friendBox">
11 <h1>Friend Finder</h1>
12 <FriendForm onFriendChange={this.loadFriendsFromServer} />
13 <FriendList data={this.state.data} />
14 </div>
15 );
16 }
17 });
1 var FriendBox = React.createClass({
2 loadFriendsFromServer: function(formData) {
3 $.get(this.props.url, formData, function(data) {
4 this.setState({ data: data.friends });
5 }.bind(this));
6 },
7
8 render: function() {
9 return (
10 <div className="friendBox">
11 <h1>Friend Finder</h1>
12 <FriendForm onFriendChange={this.loadFriendsFromServer} />
13 <FriendList data={this.state.data} />
14 </div>
15 );
16 }
17 });
More Info
• The app: http://friend-finder-react.herokuapp.com/
• Source Code: https://github.com/nurey/friend-finder

More Related Content

PPT
Selenium
PPTX
Introduction to jQuery
PDF
JS Framework Comparison - An infographic
KEY
New Perspectives on Performance
PPT
JQuery
 
PPTX
Build Tools-Introduction (3)
PDF
jQuery Keynote - Fall 2010
PPTX
jQuery Conference Chicago - September 2014
Selenium
Introduction to jQuery
JS Framework Comparison - An infographic
New Perspectives on Performance
JQuery
 
Build Tools-Introduction (3)
jQuery Keynote - Fall 2010
jQuery Conference Chicago - September 2014

What's hot (20)

PPT
Simple Singleton Java
KEY
Natural Language UI Testing using Behavior Driven Development with Pavlov and...
PDF
ITT Flisol 2013
PPTX
Latest Javascript MVC & Front End Frameworks 2017
PDF
jQuery Chicago 2014 - Next-generation JavaScript Testing
PPTX
Javascript Frameworks Comparison
PDF
Getting Started with Angular - Stormpath Webinar, January 2017
PPT
Top java script frameworks ppt
PPTX
KEY
jQuery Mobile Overview - Boston
KEY
SGCE 2012 Lightning Talk-Single Page Interface
PDF
Building a PWA with Ionic, Angular and Spring Boot - Jfokus 2017
PDF
Sxsw2013
PDF
React native - What, Why, How?
KEY
jQuery Conference Boston 2011 CouchApps
PPTX
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
PPTX
Interoperability of components built with different frameworks
PPTX
Upstate CSCI 450 jQuery
PDF
Developing java Web Applications Using Google Apps RJUG 2011
PPTX
Whats New In Spring 3.0 ?
Simple Singleton Java
Natural Language UI Testing using Behavior Driven Development with Pavlov and...
ITT Flisol 2013
Latest Javascript MVC & Front End Frameworks 2017
jQuery Chicago 2014 - Next-generation JavaScript Testing
Javascript Frameworks Comparison
Getting Started with Angular - Stormpath Webinar, January 2017
Top java script frameworks ppt
jQuery Mobile Overview - Boston
SGCE 2012 Lightning Talk-Single Page Interface
Building a PWA with Ionic, Angular and Spring Boot - Jfokus 2017
Sxsw2013
React native - What, Why, How?
jQuery Conference Boston 2011 CouchApps
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Interoperability of components built with different frameworks
Upstate CSCI 450 jQuery
Developing java Web Applications Using Google Apps RJUG 2011
Whats New In Spring 3.0 ?
Ad

Viewers also liked (9)

PDF
Matthew 8 commentary
PDF
(PEWET Workshop) (Keynote) Vincenzo De Florio - “Fractally-organized Connecti...
PPTX
Emotional intelligence
DOCX
revista digital
PDF
Interim partners nhs confederation poll results
PDF
North East HR Update 2014
PPTX
Tinyfox сайт
PDF
Benefit beat July 2015
Matthew 8 commentary
(PEWET Workshop) (Keynote) Vincenzo De Florio - “Fractally-organized Connecti...
Emotional intelligence
revista digital
Interim partners nhs confederation poll results
North East HR Update 2014
Tinyfox сайт
Benefit beat July 2015
Ad

Similar to React mini lecture (20)

PDF
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
PPTX
React, Flux and a little bit of Redux
PPTX
Heuristics to scale your framework
PPTX
ProtractorJS for automated testing of Angular 1.x/2.x applications
PDF
Why Use Rails by Dr Nic
PPTX
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
PDF
JS Class 2016
PDF
Associations & JavaScript
PDF
JS class slides (2016)
PPTX
QA Fes 2016. Александр Хотемской. Обзор ProtractorJS как фреймворка для брауз...
PDF
Ajax basics
PPTX
Welcome to React.pptx
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
PDF
Refactor Large applications with Backbone
PDF
Refactor Large apps with Backbone
PDF
Refactoring Large Web Applications with Backbone.js
PPT
An Introduction to Ruby on Rails 20100506
PPT
An introduction-to-ruby-on-rails
PDF
Using React with Grails 3
PDF
JavaScript-Core
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
React, Flux and a little bit of Redux
Heuristics to scale your framework
ProtractorJS for automated testing of Angular 1.x/2.x applications
Why Use Rails by Dr Nic
Олександр Хотемський “ProtractorJS як інструмент браузерної автоматизації для...
JS Class 2016
Associations & JavaScript
JS class slides (2016)
QA Fes 2016. Александр Хотемской. Обзор ProtractorJS как фреймворка для брауз...
Ajax basics
Welcome to React.pptx
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - Angular Summit 2015
Refactor Large applications with Backbone
Refactor Large apps with Backbone
Refactoring Large Web Applications with Backbone.js
An Introduction to Ruby on Rails 20100506
An introduction-to-ruby-on-rails
Using React with Grails 3
JavaScript-Core

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Nekopoi APK 2025 free lastest update
PDF
AI in Product Development-omnex systems
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Digital Strategies for Manufacturing Companies
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Essential Infomation Tech presentation.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
history of c programming in notes for students .pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
VVF-Customer-Presentation2025-Ver1.9.pptx
Transform Your Business with a Software ERP System
Nekopoi APK 2025 free lastest update
AI in Product Development-omnex systems
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Adobe Illustrator 28.6 Crack My Vision of Vector Design
2025 Textile ERP Trends: SAP, Odoo & Oracle
Digital Strategies for Manufacturing Companies
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
ai tools demonstartion for schools and inter college
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Essential Infomation Tech presentation.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
history of c programming in notes for students .pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily

React mini lecture

  • 1. July 5, 2015 Ilia Lobsanov A gentle introduction
  • 2. Objectives • Build a user interface by diving into code • Learn the basics of React
  • 3. What’s React? • A javascript library for building user interfaces • Great for single-page applications • Developed at Facebook/Instagram, open-sourced in 2013 • Used by Khan Academy, New York Times, Airbnb
  • 4. The Basics 1 var HelloMessage = React.createClass({ 2 render: function() { 3 return <div>Hello {this.props.name}</div>; 4 } 5 }); 6 7 React.render(<HelloMessage name="John" />, mountNode);
  • 5. The Basics 1 var HelloMessage = React.createClass({ 2 render: function() { 3 return <div>Hello {this.props.name}</div>; 4 } 5 }); 6 7 React.render(<HelloMessage name="John" />, mountNode);
  • 8. 1 var Friend = React.createClass({ 2 render: function() { 3 return ( 4 <div className="friend"> 5 <h2 className="name"> 6 {this.props.name} 7 </h2> 8 </div> 9 ); 10 } 11 });
  • 9. 1 var FriendList = React.createClass({ 2 render: function() { 3 var friendNodes = this.props.data.map(function(friend) { 4 return ( 5 <Friend name={friend.name}> 6 </Friend> 7 ); 8 }); 9 10 return ( 11 <div className="friendList"> 12 {friendNodes} 13 </div> 14 ); 15 } 16 });
  • 10. 1 var FriendForm = React.createClass({ 2 handleChange: function(e) { 3 e.preventDefault(); 4 var name = React.findDOMNode(this.refs.name).value.trim(); 5 6 this.props.onFriendChange({ 7 name: name 8 }); 9 }, 10 11 render: function() { 12 return ( 13 <form className="friendForm"> 14 Name: 15 <input type="text" ref="name" onChange={this.handleChange}/> 16 </form> 17 ); 18 } 19 });
  • 11. 1 var FriendBox = React.createClass({ 2 loadFriendsFromServer: function(formData) { 3 $.get(this.props.url, formData, function(data) { 4 this.setState({ data: data.friends }); 5 }.bind(this)); 6 }, 7 8 render: function() { 9 return ( 10 <div className="friendBox"> 11 <h1>Friend Finder</h1> 12 <FriendForm onFriendChange={this.loadFriendsFromServer} /> 13 <FriendList data={this.state.data} /> 14 </div> 15 ); 16 } 17 });
  • 12. 1 var FriendBox = React.createClass({ 2 loadFriendsFromServer: function(formData) { 3 $.get(this.props.url, formData, function(data) { 4 this.setState({ data: data.friends }); 5 }.bind(this)); 6 }, 7 8 render: function() { 9 return ( 10 <div className="friendBox"> 11 <h1>Friend Finder</h1> 12 <FriendForm onFriendChange={this.loadFriendsFromServer} /> 13 <FriendList data={this.state.data} /> 14 </div> 15 ); 16 } 17 });
  • 13. More Info • The app: http://friend-finder-react.herokuapp.com/ • Source Code: https://github.com/nurey/friend-finder

Editor's Notes

  • #5: Here we are printing “Hello John” to the screen.
  • #6: The “name” attribute of the “HelloMessage” element is set to “John”. We are referring to “John” via “this.props.name”.
  • #7: We will build a friend finder. On the left we have the initial view: a list of friends. On the right we typed the letter “j” and got a list of friends whose names start with that letter. Does this remind you of something you’ve seen online? Facebook list of friends?
  • #8: Let’s break down the interface into components.
  • #9: Let’s start with the most primitive element of the interface: the Friend. Here we are defining a React component for a Friend. The class has one function, render, which returns the html. On line 6, we are inserting the name property which we will be passing into the component.
  • #10: Now we are building a list of friends. We create a new React component representing a list of friends. At line 3, we transform a list of friend objects into a list of Friend components, which we are calling `friendNodes`. On line 5 we can see that each friend object has a name property which we pass into the Friend component as a property. At line 10, we return a div containing the list of Friend components.
  • #11: Now let’s implement the html form with the text input. Starting at line 12, we build the the form and the text input. At line 15, notice the onChange attribute. We set to this attribute to a function in the same FriendForm component. Line 2 starts the definition of the handleChange function. At line 4, we grab whatever the user typed in the Name field. We trim any extraneous whitespace with the trim function. Notice how we grabbed the name field by the ref attribute. At line 6, we send the name to another function which we will see shortly.
  • #12: Here’s the final component that composes together the previous components. You can see on line 12 where we set the onFriendChange property to a function that handles loading the friends from the server.
  • #13: The function to load the friends is an ajax request that assigns the data received from the server to the component state. The FriendList component relies on the same component state to draw the list of friends.