SlideShare uma empresa Scribd logo
1 de 57
ReactJS for Beginners
Oswald Campesato
Consultant/Training:
www.iquarkt.com
ocampesato@yahoo.com
Features of ReactJS
• Beta status
• component-based architecture
• loosely coupled components
• less code more application focus
• Supports ES6
What are Transpilers?
• They convert code from one language to another
• Babel (formerly 6to5):
+converts ES6 (some ES7) to ECMA5
+ appears to be the de facto standard
• Traceur (Google):
+ converts ES6 to ECMA5
+ used by Angular 2
Download/Install Code Samples
• 1) download/unzip Github repo (or clone repo)
• 2) npm install
• 3) double-click on the HTML Web page
React App (MyWebPage.html)
<!– 1) The core React library -->
<script src="https://fb.me/react-0.14.3.js"></script>
<!– 2) The ReactDOM Library -->
<script src="https://fb.me/react-dom-0.14.3.js"></script>
<!– 3) For transpiling ES6 code into ES5 code -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-
core/5.8.23/browser.min.js">
</script>
ReactJS “Hello World” (Version 1)
• <body>
• <div id="hello"></div>
•
• <script>
• ReactDOM.render(
• React.DOM.h1(null, "Hello World"),
• document.getElementById('hello'));
• </script>
• </body>
• NB: Babel.js is not required in this example
ReactJS “Hello World” (Version 2)
• <body>
• <div id="hello"></div>
•
• <script type="text/babel">
• ReactDOM.render(
• React.DOM.h1(null, "Hello World"),
• document.getElementById('hello'));
• </script>
• </body>
ReactJS “Hello World” (Version 3)
• <body>
• <div id="hello"></div>
• <script type="text/babel">
• var Hello = React.createClass({ // deprecated in 0.14.3
• render: function () {
• return ( <h1>Hello World</h1> );
• }
• });
• ReactDOM.render(<Hello/>,
• document.getElementById('hello'));
• </script>
• </body>
ReactJS “Hello World” (Version 4)
• <body>
• <div id="hello"></div>
• <script type="text/babel">
• class Hello extends React.Component { // recommended
• constructor () {
• super();
• }
• render() {
• return <div>Hello World</div>
• }
• }
• ReactDOM.render(<Hello/>,
• document.getElementById('hello'));
• </script>
Using “Props” in ReactJS
• <div id="hello"></div>
• <script type="text/babel">
• var Hello = React.createClass({ // deprecated in 0.14.3
• render: function () {
• var name = this.props.name;
•
• return ( <h2>Hello {name}</h2> );
• }
• });
• ReactDOM.render(<Hello name="Dave"/>,
• document.getElementById('hello'));
• </script>
Property Types in ReactJS
• propTypes contains properties and their types:
• propTypes: {
• width: React.PropTypes.number,
• height: React.PropTypes.number
• //other1: React.PropTypes.string,
• //other2: React.PropTypes.array.isRequired,
• },
• See: ReactSVGRandom1.html
Property Types and Validation
• Throw an error if any property is negative:
• propTypes: {
• width: function(props, propName, componentName) {
• if(props[propName] < 0) {
• throw new Error(propName+" cannot be negative");
• }
• }
• },
• See: PropertyValidation.html
The “getDefaultProps()” Method
• <div id="container"></div>
• <script type="text/babel">
• var Hello = React.createClass({
• getDefaultProps: function () {
• return { y : 456 }
• },
• render: function () {
• return (
• <h2>x = {this.props.x} y = {this.props.y} </h2>
• );
• }
• });
ReactDOM.render(<Hello x={123}/>,
• document.getElementById('container'));
• </script>
Exercise: convert to ES6
• The previous example uses the deprecated syntax
• Convert the code to the “extend” style (used in 0.14.3)
• Hint: look at one of the previous “Hello World” examples
Handling Mouse Events
• class MouseOverButton extends React.Component {
• // constructor …
• render() {
• console.log("rendering button...");
• return (
• <button onClick={this.update}>ClickMe</button>
• );
• }
• update() {
• console.log("inside update");
• }
• }
Working with Lists (1a)
• <div id="noreactstuff">
• <p>Standard HTML User List:</p>
• <ul>
• <li>Sara</li>
• <li>Dave</li>
• <li>John</li>
• <li>Sally</li>
• </ul>
• </div>
Working with Lists (1b)
• class UserList extends React.Component {
• render() {
• return (
• <ul>
• <li>Sara</li>
• <li>Dave</li>
• <li>John</li>
• <li>Sally</li>
• </ul>
• )
• }
• }
• ReactDOM.render(
• <UserList/>,
• document.getElementById('container')
• )
Working with Lists (2a)
• class UserList extends React.Component {
• render() {
• return (
• <ul>
• <ListOptions value="Sara" />
• <ListOptions value="Dave" />
• <ListOptions value="John" />
• <ListOptions value="Sally" />
• </ul>
• )
• }
• }
Working with Lists (2b)
• class ListOptions extends React.Component {
• render() {
• return (
• <li>{this.props.value}</li>
• )
• }
• }
• ReactDOM.render(
• <UserList/>,
• document.getElementById('container')
• )
SVG in ReactJS (part 1)
• <div id="mysvg2"></div>
• <script type="text/babel">
• class MySVG2 extends React.Component {
• constructor () {
• super();
• }
•
SVG in ReactJS (part 2)
• render() {
• return (
• <svg width="600" height="200">
• <g transform="translate(50, 20)">
• <rect width="160" height="80" fill="red"/>
• </g>
• </svg>
• );
• }
• }
• ReactDOM.render(<MySVG2 />,
• document.getElementById("mysvg2"));
• </script>
Images and Nested Components (1)
• <div id="people"></div>
•
• <script type="text/babel">
• var people = [
• {
• name : "John Smith", img: "sample1.png",
• },
• {
• name : "Jane Jones", img: "sample2.png",
• },
• {
• name : "Dave Edwards", img: "sample3.png",
• }
• ];
Images and Nested Components (2)
• class Outer extends React.Component {
• render () {
• return (
• <div>
• <h2>A List of People:</h2> <!-- data = people -->
• <h3><Person name={this.props.data[0].name}
• img={this.props.data[0].img} /></h3>
• <h3><Person name={this.props.data[1].name}
• img={this.props.data[1].img} /></h3>
• <h3><Person name={this.props.data[2].name}
• img={this.props.data[2].img} /></h3>
• </div>
• );
• }
• }
Images and Nested Components (3)
• class Person extends React.Component {
• render() {
• return (
• <table>
• <tbody>
• <tr> <!– name and img belong to one ‘people row’ -->
• <td> {this.props.name} </td>
• <td><img src={this.props.img} width="100" height="100"/></td>
• </tr>
• </tbody>
• </table>
• );
• }
• }
• ReactDOM.render(<Outer data={people}/>,
• document.getElementById('people'));
Exercise: Add More Data
• Add a city field to the previous application
Conditional Execution (1)
• <div id="hello"></div>
• <script type="text/babel">
• class Hello1 extends React.Component {
• render () {
• return (
• <h2>Hello World1</h2>
• );
• }
• }
Conditional Execution (2)
• class Hello2 extends React.Component {
• render() {
• return (
• <h2>Hello World2</h2>
• );
• }
• }
Conditional Execution (3)
• ReactDOM.render(
• <div>
• { Math.random() > 0.5 ? <Hello1 /> : <Hello2 />}
• </div>,
• document.getElementById('hello')
• );
• </script>
The ‘map’ and ‘filter’ Functions
• The next “list” exercises involves the ‘map’ function
• var items = [1,2,3,4,5,6,7,8,9,10,11,
• 12,13,14,15,16,17,18,19,20];
• var even = [], double = [];
• even = items.filter(function(item) {
• return item % 2 == 0;
• });
• console.log("even = "+even);
• double = items.map(function(item) {
• return item * 2;
• });
• console.log("double = "+double);
Working with Lists (3a)
• class UserList extends React.Component {
• constructor() {
• super();
• this.userList = [ 'Sara', 'Dave', 'John', 'Sally’];
• }
•
• render() {
• return (
• <ul>
• <ListOptions options={this.userList} />
• </ul>
• )
• }
• }
Working with Lists (3b)
• class ListOptions extends React.Component {
• render() {
• return (
• <div>
• {this.props.options.map(function(option) {
• return (
• <li key={option}>{option}</li>
• )
• })}
• </div>
• )
• }
• }
Echoing User Input in ReactJS
• class Echo extends React.Component {
• constructor() {
• super();
• }
• render() {
• return (
• <input type="text" onChange={this.handleChange} />
• );
• }
• handleChange(e) {
• console.log(e.target.value);
• }
• }
•
• ReactDOM.render(<Echo />, document.getElementById("content"));
ReactJS: Lifecycle methods
• Before/during/after component ‘mounting’:
• componentWillMount: function() {
• this.doSomething1();
• },
• componentShouldMount: function() {
• this.doSomething2();
• },
• componentShouldUpdate: function() {
• this.doSomething2();
• },
• componentDidMount: function() {
• this.doSomething2();
• },
• componentWillUnmount: function() {
• this.doSomething2();
• },
Working with State (1a)
• class MyInput extends React.Component {
• constructor() {
• super();
• }
• componentWillMount() {
• this.state = {value: 'Hello There!'};
• }
• handleChange(event) {
• this.setState({value: event.target.value});
• console.log("value: "+this.state.value);
• }
Working with State (1b)
• render() {
• var value = this.state.value;
• return <input type="text" value={value}
• onChange={this.handleChange} />;
• }
• }
• ReactDOM.render(
• <MyInput />,
• document.getElementById('myinput')
• );
Update List of Users (1)
• class UserList extends React.Component {
• constructor() {
• super();
• this.userList = ['Sara', 'Dave', 'John', 'Sally’ ];
• this.addUser = this.addUser.bind(this);
• }
• componentDidMount() {
• this.setState({user: ""});
• }
• addUser() {
• var user = this.refs.user.value;
• //console.log("user = "+user);
• this.setState({user: user});
• this.userList.push(user);
• }
Update List of Users (2)
• render() {
• return (
• <div>
• <ul>
• <ListOptions options={this.userList} />
• </ul>
• <input ref="user" type="text" />
• <button onClick={this.addUser}>Add User</button>
• </div>
• )
• }
• }
Update List of Users (3)
• class ListOptions extends React.Component {
• render() {
• return (
• <div>
• {this.props.options.map(function(option) { // options = userList
• return (
• <li key={option}>{option}</li>
• )
• })}
• </div>
• )
• }
• }
• ReactDOM.render(
• <UserList/>,
• document.getElementById('container')
• )
Exercises: List of Users via JSON Data
• 1a) Replace the array of names with this data:
• this.userList = [
• { name: 'Sara'},
• { name: 'Dave'},
• { name: 'John'},
• { name: 'Sally’} ];
• }
• 1b) update the code to reflect the modified data structure
• 2a) replace ‘name’ with ‘fname’
• 2b) also add an ‘lname’ property
• 3b) update the code to reflect the modified data structure
Working with JSON Data Files
• Read the contents of this text file and display the data:
• [
• {"fname":"Jane","lname":"Jones","city":"San Francisco"},
• {"fname":"John","lname":"Smith","city":"New York"},
• {"fname":"Dave","lname":"Stone","city":"Seattle"},
• {"fname":"Sara","lname":"Edson","city":"Chicago"}
• ]
Working with JSON Data Files (1a)
• class UserInfo extends React.Component {
• constructor() {
• super();
• }
• componentWillMount() {
• this.state = { loading: true, error: null, data: null};
• }
•
• componentDidMount() {
• this.props.promise.then(
• value => this.setState({loading: false, data: value}),
• error => this.setState({loading: false, error: error}));
• }
Working with JSON Data Files (1b)
• render() {
• if (this.state.loading) {
• return <span>Loading...</span>;
• }
• else if (this.state.error !== null) {
• return <span>Error: {this.state.error.message}</span>;
• }
• else {
• let empItems = this.state.data.map( emp => {
• return <li key={emp.fname}>{emp.fname}</li>
• })
• return (
• <div>
• <ul>{empItems}</ul>
• </div>
• )
• }}
Retrieving Github User Data (1)
• class UserInfo extends React.Component {
• constructor() {
• super();
• }
• componentWillMount() {
• this.state = { loading: true, error: null, data: null};
• }
•
• componentDidMount() {
• this.props.promise.then(
• value => this.setState({loading: false, data: value}),
• error => this.setState({loading: false, error: error}));
• }
Retrieving Github User Data (2)
• render() {
• if (this.state.loading) {
• return <span>Loading...</span>;
• }
• else if (this.state.error !== null) {
• return <span>Error: {this.state.error.message}</span>;
• }
• else {
• var userInfo = this.state.data;
• return (
• <div>
• <li>Username: {userInfo.login} </li>
• <li>Followers: {userInfo.followers} </li>
• <li>Following: {userInfo.following} </li>
• <li>Created at: {userInfo.created_at}</li>
• </div>
• )
• }}}
Retrieving Github User Data (3)
• ReactDOM.render(
• <UserInfo
promise={$.getJSON('https://api.github.com/users/ocampesato')} />,
• document.getElementById("userinfo")
• );
What about ES6?
• Arrow functions and let keyword
• Block scopes
• Classes and inheritance
• Default parameters
• Destructured assignment
• Generators, Iterators, Maps, and Sets
• Promises and Rest parameters
• Spread operator
• Template Literals
ES6 let and Arrow Functions
• let square = x => x * x;
• let add = (x, y) => x + y;
• let pi = () => 3.1415;
• console.log(square(8)); // 64
• console.log(add(5, 9)); // 14
• console.log(pi()); // 3.1415
ES6 Class Definition (part 1)
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
calcArea() {
return this.height * this.width;
}
}
• var r1 = new Rectangle(5,10);
• var r2 = new Rectangle(25,15);
ES6 Class Definition (part 2)
• console.log("r1 area = "+r1.calcArea());
• console.log("r2 area = "+r2.calcArea());
• Test this code here:
http://babeljs.io/repl/
• More Examples:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Classes
Convert JSON Data to ES6 Class (1)
• Consider the following array of data:
var people = [
{fname:"Jane",lname:"Smith",zip:"94043"},
{fname:"John",lname:"Jones",zip:"94539"},
{fname:"Dave",lname:"Starr",zip:"67800"}
]
Convert JSON Data to ES6 Class (2)
class People {
• public fname:string;
• public lname:string;
• public zip:string;
• constructor(public fname:string,
• public lname:string,
• public zip:string) {
• this.fname = fname;
• this.lname = lname;
• this.zip = zip;
• }
}
Convert JSON Data to ES6 Class (3)
• Array of ES6 objects:
var ES6People = [
new People("Jane","Smith","94043"),
new People("John","Jones","94539"),
new People("Dave","Starr","67800")
];
Useful Tools/IDEs
• Select an IDE:
+WebStorm 10: free 30-day trial ($49/year)
+Visual Studio Code (free)
+ Atom (free) with atom-TypeScript extension
• Command Line Tools:
+ npm, npmjs, gulp, grunt (older), broccoli,
+ webpack, browserify (older), jspm+systemjs
https://github.com/addyosmani/es6-tools
Useful Technologies to Learn
• Main features of ES6
• Sass/Bootstrap 4 (previous: less)
• D3.js for Data Visualization
• React Native (=React for Mobile)
• https://egghead.io/react-redux-cheatsheets
Browser Status for ES6
• Modern IE: https://goo.gl/56n7IL
• Mozilla: https://goo.gl/iSNDf9
• Chrome: https://www.chromestatus.com/features#ES6
Other Useful ES6 Links
https://github.com/lukehoban/es6features
http://kangax.github.io/compat-table/es6/
https://dev.modern.ie/platform/status/?filter=f3f0000bf&search=es6
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_i
n_Mozilla
https://medium.com/@bojzi/overview-of-the-javascript-ecosystem-
8ec4a0b7a7be
Recent/Upcoming Books and Training
1) HTML5 Canvas and CSS3 Graphics (2013)
2) jQuery, CSS3, and HTML5 for Mobile (2013)
3) HTML5 Pocket Primer (2013)
4) jQuery Pocket Primer (2013)
5) HTML5 Mobile Pocket Primer (2014)
6) D3 Pocket Primer (2015)
7) Python Pocket Primer (2015)
8) SVG Pocket Primer (2016)
9) CSS3 Pocket Primer (2016)
10) Angular Pocket Primer (2016)

Mais conteúdo relacionado

Mais procurados

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 NativeEric Deng
 
React – Structure Container Component In Meteor
 React – Structure Container Component In Meteor React – Structure Container Component In Meteor
React – Structure Container Component In MeteorDesignveloper
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJSAll Things Open
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developerEugene Zharkov
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overviewAlex Bachuk
 
Getting started with ReactJS
Getting started with ReactJSGetting started with ReactJS
Getting started with ReactJSKrishna Sunuwar
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingBinary Studio
 
React for Dummies
React for DummiesReact for Dummies
React for DummiesMitch Chen
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorialMohammed Fazuluddin
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
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
 

Mais procurados (20)

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
 
React / Redux Architectures
React / Redux ArchitecturesReact / Redux Architectures
React / Redux Architectures
 
React – Structure Container Component In Meteor
 React – Structure Container Component In Meteor React – Structure Container Component In Meteor
React – Structure Container Component In Meteor
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
React JS part 1
React JS part 1React JS part 1
React JS part 1
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
React js
React jsReact js
React js
 
Getting started with ReactJS
Getting started with ReactJSGetting started with ReactJS
Getting started with ReactJS
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
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 programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 

Destaque

NY Web Performance - DNS as a Web Performance Tool
NY Web Performance - DNS as a Web Performance ToolNY Web Performance - DNS as a Web Performance Tool
NY Web Performance - DNS as a Web Performance ToolNS1
 
Bend dynamics and perceptions with conflict resolution and emotional safety tips
Bend dynamics and perceptions with conflict resolution and emotional safety tipsBend dynamics and perceptions with conflict resolution and emotional safety tips
Bend dynamics and perceptions with conflict resolution and emotional safety tipsJenn Turner
 
Functional Reactive Programming in Javascript
Functional Reactive Programming in JavascriptFunctional Reactive Programming in Javascript
Functional Reactive Programming in JavascriptBrian Lonsdorf
 
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)Guy Podjarny
 
Intel XDK - Philly JS
Intel XDK - Philly JSIntel XDK - Philly JS
Intel XDK - Philly JSIan Maffett
 
React For Vikings
React For VikingsReact For Vikings
React For VikingsFITC
 

Destaque (11)

ReactJS
ReactJSReactJS
ReactJS
 
NY Web Performance - DNS as a Web Performance Tool
NY Web Performance - DNS as a Web Performance ToolNY Web Performance - DNS as a Web Performance Tool
NY Web Performance - DNS as a Web Performance Tool
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Bend dynamics and perceptions with conflict resolution and emotional safety tips
Bend dynamics and perceptions with conflict resolution and emotional safety tipsBend dynamics and perceptions with conflict resolution and emotional safety tips
Bend dynamics and perceptions with conflict resolution and emotional safety tips
 
do u webview?
do u webview?do u webview?
do u webview?
 
Design+Performance
Design+PerformanceDesign+Performance
Design+Performance
 
Functional Reactive Programming in Javascript
Functional Reactive Programming in JavascriptFunctional Reactive Programming in Javascript
Functional Reactive Programming in Javascript
 
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
 
Intel XDK - Philly JS
Intel XDK - Philly JSIntel XDK - Philly JS
Intel XDK - Philly JS
 
React For Vikings
React For VikingsReact For Vikings
React For Vikings
 
ReactJs
ReactJsReactJs
ReactJs
 

Semelhante a ReactJS for Beginners

Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript名辰 洪
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Angularjs Test Driven Development (TDD)
Angularjs Test Driven Development (TDD)Angularjs Test Driven Development (TDD)
Angularjs Test Driven Development (TDD)Anis Bouhachem Djer
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
Tools that get you laid
Tools that get you laidTools that get you laid
Tools that get you laidSwizec Teller
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationSean Burgess
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsFITC
 
ReactでGraphQLを使っている
ReactでGraphQLを使っているReactでGraphQLを使っている
ReactでGraphQLを使っているTakahiro Kobaru
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 
The Future of Plugin Dev
The Future of Plugin DevThe Future of Plugin Dev
The Future of Plugin DevBrandon Kelly
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript FrameworkAll Things Open
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}.toster
 

Semelhante a ReactJS for Beginners (20)

Universal JavaScript
Universal JavaScriptUniversal JavaScript
Universal JavaScript
 
React inter3
React inter3React inter3
React inter3
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
Angularjs Test Driven Development (TDD)
Angularjs Test Driven Development (TDD)Angularjs Test Driven Development (TDD)
Angularjs Test Driven Development (TDD)
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
Tools that get you laid
Tools that get you laidTools that get you laid
Tools that get you laid
 
JS Essence
JS EssenceJS Essence
JS Essence
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
 
ReactでGraphQLを使っている
ReactでGraphQLを使っているReactでGraphQLを使っている
ReactでGraphQLを使っている
 
J query module1
J query module1J query module1
J query module1
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 
The Future of Plugin Dev
The Future of Plugin DevThe Future of Plugin Dev
The Future of Plugin Dev
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript Framework
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 

Mais de Oswald Campesato

Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)Oswald Campesato
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasOswald Campesato
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep LearningOswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
"An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning""An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning"Oswald Campesato
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowOswald Campesato
 
Introduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersIntroduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersOswald Campesato
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your BrowserOswald Campesato
 
Deep Learning in Your Browser
Deep Learning in Your BrowserDeep Learning in Your Browser
Deep Learning in Your BrowserOswald Campesato
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
Introduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowIntroduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowOswald Campesato
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsIntro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsOswald Campesato
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowOswald Campesato
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Deep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLDeep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLOswald Campesato
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowOswald Campesato
 

Mais de Oswald Campesato (20)

Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep Learning
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
"An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning""An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning"
 
H2 o berkeleydltf
H2 o berkeleydltfH2 o berkeleydltf
H2 o berkeleydltf
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and Tensorflow
 
Introduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersIntroduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-Programmers
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your Browser
 
Deep Learning in Your Browser
Deep Learning in Your BrowserDeep Learning in Your Browser
Deep Learning in Your Browser
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
Introduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowIntroduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlow
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsIntro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.js
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and Tensorflow
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Deep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLDeep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGL
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
 
C++ and Deep Learning
C++ and Deep LearningC++ and Deep Learning
C++ and Deep Learning
 

Último

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 

Último (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

ReactJS for Beginners

  • 1. ReactJS for Beginners Oswald Campesato Consultant/Training: www.iquarkt.com ocampesato@yahoo.com
  • 2. Features of ReactJS • Beta status • component-based architecture • loosely coupled components • less code more application focus • Supports ES6
  • 3. What are Transpilers? • They convert code from one language to another • Babel (formerly 6to5): +converts ES6 (some ES7) to ECMA5 + appears to be the de facto standard • Traceur (Google): + converts ES6 to ECMA5 + used by Angular 2
  • 4. Download/Install Code Samples • 1) download/unzip Github repo (or clone repo) • 2) npm install • 3) double-click on the HTML Web page
  • 5. React App (MyWebPage.html) <!– 1) The core React library --> <script src="https://fb.me/react-0.14.3.js"></script> <!– 2) The ReactDOM Library --> <script src="https://fb.me/react-dom-0.14.3.js"></script> <!– 3) For transpiling ES6 code into ES5 code --> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel- core/5.8.23/browser.min.js"> </script>
  • 6. ReactJS “Hello World” (Version 1) • <body> • <div id="hello"></div> • • <script> • ReactDOM.render( • React.DOM.h1(null, "Hello World"), • document.getElementById('hello')); • </script> • </body> • NB: Babel.js is not required in this example
  • 7. ReactJS “Hello World” (Version 2) • <body> • <div id="hello"></div> • • <script type="text/babel"> • ReactDOM.render( • React.DOM.h1(null, "Hello World"), • document.getElementById('hello')); • </script> • </body>
  • 8. ReactJS “Hello World” (Version 3) • <body> • <div id="hello"></div> • <script type="text/babel"> • var Hello = React.createClass({ // deprecated in 0.14.3 • render: function () { • return ( <h1>Hello World</h1> ); • } • }); • ReactDOM.render(<Hello/>, • document.getElementById('hello')); • </script> • </body>
  • 9. ReactJS “Hello World” (Version 4) • <body> • <div id="hello"></div> • <script type="text/babel"> • class Hello extends React.Component { // recommended • constructor () { • super(); • } • render() { • return <div>Hello World</div> • } • } • ReactDOM.render(<Hello/>, • document.getElementById('hello')); • </script>
  • 10. Using “Props” in ReactJS • <div id="hello"></div> • <script type="text/babel"> • var Hello = React.createClass({ // deprecated in 0.14.3 • render: function () { • var name = this.props.name; • • return ( <h2>Hello {name}</h2> ); • } • }); • ReactDOM.render(<Hello name="Dave"/>, • document.getElementById('hello')); • </script>
  • 11. Property Types in ReactJS • propTypes contains properties and their types: • propTypes: { • width: React.PropTypes.number, • height: React.PropTypes.number • //other1: React.PropTypes.string, • //other2: React.PropTypes.array.isRequired, • }, • See: ReactSVGRandom1.html
  • 12. Property Types and Validation • Throw an error if any property is negative: • propTypes: { • width: function(props, propName, componentName) { • if(props[propName] < 0) { • throw new Error(propName+" cannot be negative"); • } • } • }, • See: PropertyValidation.html
  • 13. The “getDefaultProps()” Method • <div id="container"></div> • <script type="text/babel"> • var Hello = React.createClass({ • getDefaultProps: function () { • return { y : 456 } • }, • render: function () { • return ( • <h2>x = {this.props.x} y = {this.props.y} </h2> • ); • } • }); ReactDOM.render(<Hello x={123}/>, • document.getElementById('container')); • </script>
  • 14. Exercise: convert to ES6 • The previous example uses the deprecated syntax • Convert the code to the “extend” style (used in 0.14.3) • Hint: look at one of the previous “Hello World” examples
  • 15. Handling Mouse Events • class MouseOverButton extends React.Component { • // constructor … • render() { • console.log("rendering button..."); • return ( • <button onClick={this.update}>ClickMe</button> • ); • } • update() { • console.log("inside update"); • } • }
  • 16. Working with Lists (1a) • <div id="noreactstuff"> • <p>Standard HTML User List:</p> • <ul> • <li>Sara</li> • <li>Dave</li> • <li>John</li> • <li>Sally</li> • </ul> • </div>
  • 17. Working with Lists (1b) • class UserList extends React.Component { • render() { • return ( • <ul> • <li>Sara</li> • <li>Dave</li> • <li>John</li> • <li>Sally</li> • </ul> • ) • } • } • ReactDOM.render( • <UserList/>, • document.getElementById('container') • )
  • 18. Working with Lists (2a) • class UserList extends React.Component { • render() { • return ( • <ul> • <ListOptions value="Sara" /> • <ListOptions value="Dave" /> • <ListOptions value="John" /> • <ListOptions value="Sally" /> • </ul> • ) • } • }
  • 19. Working with Lists (2b) • class ListOptions extends React.Component { • render() { • return ( • <li>{this.props.value}</li> • ) • } • } • ReactDOM.render( • <UserList/>, • document.getElementById('container') • )
  • 20. SVG in ReactJS (part 1) • <div id="mysvg2"></div> • <script type="text/babel"> • class MySVG2 extends React.Component { • constructor () { • super(); • } •
  • 21. SVG in ReactJS (part 2) • render() { • return ( • <svg width="600" height="200"> • <g transform="translate(50, 20)"> • <rect width="160" height="80" fill="red"/> • </g> • </svg> • ); • } • } • ReactDOM.render(<MySVG2 />, • document.getElementById("mysvg2")); • </script>
  • 22. Images and Nested Components (1) • <div id="people"></div> • • <script type="text/babel"> • var people = [ • { • name : "John Smith", img: "sample1.png", • }, • { • name : "Jane Jones", img: "sample2.png", • }, • { • name : "Dave Edwards", img: "sample3.png", • } • ];
  • 23. Images and Nested Components (2) • class Outer extends React.Component { • render () { • return ( • <div> • <h2>A List of People:</h2> <!-- data = people --> • <h3><Person name={this.props.data[0].name} • img={this.props.data[0].img} /></h3> • <h3><Person name={this.props.data[1].name} • img={this.props.data[1].img} /></h3> • <h3><Person name={this.props.data[2].name} • img={this.props.data[2].img} /></h3> • </div> • ); • } • }
  • 24. Images and Nested Components (3) • class Person extends React.Component { • render() { • return ( • <table> • <tbody> • <tr> <!– name and img belong to one ‘people row’ --> • <td> {this.props.name} </td> • <td><img src={this.props.img} width="100" height="100"/></td> • </tr> • </tbody> • </table> • ); • } • } • ReactDOM.render(<Outer data={people}/>, • document.getElementById('people'));
  • 25. Exercise: Add More Data • Add a city field to the previous application
  • 26. Conditional Execution (1) • <div id="hello"></div> • <script type="text/babel"> • class Hello1 extends React.Component { • render () { • return ( • <h2>Hello World1</h2> • ); • } • }
  • 27. Conditional Execution (2) • class Hello2 extends React.Component { • render() { • return ( • <h2>Hello World2</h2> • ); • } • }
  • 28. Conditional Execution (3) • ReactDOM.render( • <div> • { Math.random() > 0.5 ? <Hello1 /> : <Hello2 />} • </div>, • document.getElementById('hello') • ); • </script>
  • 29. The ‘map’ and ‘filter’ Functions • The next “list” exercises involves the ‘map’ function • var items = [1,2,3,4,5,6,7,8,9,10,11, • 12,13,14,15,16,17,18,19,20]; • var even = [], double = []; • even = items.filter(function(item) { • return item % 2 == 0; • }); • console.log("even = "+even); • double = items.map(function(item) { • return item * 2; • }); • console.log("double = "+double);
  • 30. Working with Lists (3a) • class UserList extends React.Component { • constructor() { • super(); • this.userList = [ 'Sara', 'Dave', 'John', 'Sally’]; • } • • render() { • return ( • <ul> • <ListOptions options={this.userList} /> • </ul> • ) • } • }
  • 31. Working with Lists (3b) • class ListOptions extends React.Component { • render() { • return ( • <div> • {this.props.options.map(function(option) { • return ( • <li key={option}>{option}</li> • ) • })} • </div> • ) • } • }
  • 32. Echoing User Input in ReactJS • class Echo extends React.Component { • constructor() { • super(); • } • render() { • return ( • <input type="text" onChange={this.handleChange} /> • ); • } • handleChange(e) { • console.log(e.target.value); • } • } • • ReactDOM.render(<Echo />, document.getElementById("content"));
  • 33. ReactJS: Lifecycle methods • Before/during/after component ‘mounting’: • componentWillMount: function() { • this.doSomething1(); • }, • componentShouldMount: function() { • this.doSomething2(); • }, • componentShouldUpdate: function() { • this.doSomething2(); • }, • componentDidMount: function() { • this.doSomething2(); • }, • componentWillUnmount: function() { • this.doSomething2(); • },
  • 34. Working with State (1a) • class MyInput extends React.Component { • constructor() { • super(); • } • componentWillMount() { • this.state = {value: 'Hello There!'}; • } • handleChange(event) { • this.setState({value: event.target.value}); • console.log("value: "+this.state.value); • }
  • 35. Working with State (1b) • render() { • var value = this.state.value; • return <input type="text" value={value} • onChange={this.handleChange} />; • } • } • ReactDOM.render( • <MyInput />, • document.getElementById('myinput') • );
  • 36. Update List of Users (1) • class UserList extends React.Component { • constructor() { • super(); • this.userList = ['Sara', 'Dave', 'John', 'Sally’ ]; • this.addUser = this.addUser.bind(this); • } • componentDidMount() { • this.setState({user: ""}); • } • addUser() { • var user = this.refs.user.value; • //console.log("user = "+user); • this.setState({user: user}); • this.userList.push(user); • }
  • 37. Update List of Users (2) • render() { • return ( • <div> • <ul> • <ListOptions options={this.userList} /> • </ul> • <input ref="user" type="text" /> • <button onClick={this.addUser}>Add User</button> • </div> • ) • } • }
  • 38. Update List of Users (3) • class ListOptions extends React.Component { • render() { • return ( • <div> • {this.props.options.map(function(option) { // options = userList • return ( • <li key={option}>{option}</li> • ) • })} • </div> • ) • } • } • ReactDOM.render( • <UserList/>, • document.getElementById('container') • )
  • 39. Exercises: List of Users via JSON Data • 1a) Replace the array of names with this data: • this.userList = [ • { name: 'Sara'}, • { name: 'Dave'}, • { name: 'John'}, • { name: 'Sally’} ]; • } • 1b) update the code to reflect the modified data structure • 2a) replace ‘name’ with ‘fname’ • 2b) also add an ‘lname’ property • 3b) update the code to reflect the modified data structure
  • 40. Working with JSON Data Files • Read the contents of this text file and display the data: • [ • {"fname":"Jane","lname":"Jones","city":"San Francisco"}, • {"fname":"John","lname":"Smith","city":"New York"}, • {"fname":"Dave","lname":"Stone","city":"Seattle"}, • {"fname":"Sara","lname":"Edson","city":"Chicago"} • ]
  • 41. Working with JSON Data Files (1a) • class UserInfo extends React.Component { • constructor() { • super(); • } • componentWillMount() { • this.state = { loading: true, error: null, data: null}; • } • • componentDidMount() { • this.props.promise.then( • value => this.setState({loading: false, data: value}), • error => this.setState({loading: false, error: error})); • }
  • 42. Working with JSON Data Files (1b) • render() { • if (this.state.loading) { • return <span>Loading...</span>; • } • else if (this.state.error !== null) { • return <span>Error: {this.state.error.message}</span>; • } • else { • let empItems = this.state.data.map( emp => { • return <li key={emp.fname}>{emp.fname}</li> • }) • return ( • <div> • <ul>{empItems}</ul> • </div> • ) • }}
  • 43. Retrieving Github User Data (1) • class UserInfo extends React.Component { • constructor() { • super(); • } • componentWillMount() { • this.state = { loading: true, error: null, data: null}; • } • • componentDidMount() { • this.props.promise.then( • value => this.setState({loading: false, data: value}), • error => this.setState({loading: false, error: error})); • }
  • 44. Retrieving Github User Data (2) • render() { • if (this.state.loading) { • return <span>Loading...</span>; • } • else if (this.state.error !== null) { • return <span>Error: {this.state.error.message}</span>; • } • else { • var userInfo = this.state.data; • return ( • <div> • <li>Username: {userInfo.login} </li> • <li>Followers: {userInfo.followers} </li> • <li>Following: {userInfo.following} </li> • <li>Created at: {userInfo.created_at}</li> • </div> • ) • }}}
  • 45. Retrieving Github User Data (3) • ReactDOM.render( • <UserInfo promise={$.getJSON('https://api.github.com/users/ocampesato')} />, • document.getElementById("userinfo") • );
  • 46. What about ES6? • Arrow functions and let keyword • Block scopes • Classes and inheritance • Default parameters • Destructured assignment • Generators, Iterators, Maps, and Sets • Promises and Rest parameters • Spread operator • Template Literals
  • 47. ES6 let and Arrow Functions • let square = x => x * x; • let add = (x, y) => x + y; • let pi = () => 3.1415; • console.log(square(8)); // 64 • console.log(add(5, 9)); // 14 • console.log(pi()); // 3.1415
  • 48. ES6 Class Definition (part 1) class Rectangle { constructor(height, width) { this.height = height; this.width = width; } calcArea() { return this.height * this.width; } } • var r1 = new Rectangle(5,10); • var r2 = new Rectangle(25,15);
  • 49. ES6 Class Definition (part 2) • console.log("r1 area = "+r1.calcArea()); • console.log("r2 area = "+r2.calcArea()); • Test this code here: http://babeljs.io/repl/ • More Examples: https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Classes
  • 50. Convert JSON Data to ES6 Class (1) • Consider the following array of data: var people = [ {fname:"Jane",lname:"Smith",zip:"94043"}, {fname:"John",lname:"Jones",zip:"94539"}, {fname:"Dave",lname:"Starr",zip:"67800"} ]
  • 51. Convert JSON Data to ES6 Class (2) class People { • public fname:string; • public lname:string; • public zip:string; • constructor(public fname:string, • public lname:string, • public zip:string) { • this.fname = fname; • this.lname = lname; • this.zip = zip; • } }
  • 52. Convert JSON Data to ES6 Class (3) • Array of ES6 objects: var ES6People = [ new People("Jane","Smith","94043"), new People("John","Jones","94539"), new People("Dave","Starr","67800") ];
  • 53. Useful Tools/IDEs • Select an IDE: +WebStorm 10: free 30-day trial ($49/year) +Visual Studio Code (free) + Atom (free) with atom-TypeScript extension • Command Line Tools: + npm, npmjs, gulp, grunt (older), broccoli, + webpack, browserify (older), jspm+systemjs https://github.com/addyosmani/es6-tools
  • 54. Useful Technologies to Learn • Main features of ES6 • Sass/Bootstrap 4 (previous: less) • D3.js for Data Visualization • React Native (=React for Mobile) • https://egghead.io/react-redux-cheatsheets
  • 55. Browser Status for ES6 • Modern IE: https://goo.gl/56n7IL • Mozilla: https://goo.gl/iSNDf9 • Chrome: https://www.chromestatus.com/features#ES6
  • 56. Other Useful ES6 Links https://github.com/lukehoban/es6features http://kangax.github.io/compat-table/es6/ https://dev.modern.ie/platform/status/?filter=f3f0000bf&search=es6 https://developer.mozilla.org/en- US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_i n_Mozilla https://medium.com/@bojzi/overview-of-the-javascript-ecosystem- 8ec4a0b7a7be
  • 57. Recent/Upcoming Books and Training 1) HTML5 Canvas and CSS3 Graphics (2013) 2) jQuery, CSS3, and HTML5 for Mobile (2013) 3) HTML5 Pocket Primer (2013) 4) jQuery Pocket Primer (2013) 5) HTML5 Mobile Pocket Primer (2014) 6) D3 Pocket Primer (2015) 7) Python Pocket Primer (2015) 8) SVG Pocket Primer (2016) 9) CSS3 Pocket Primer (2016) 10) Angular Pocket Primer (2016)