SlideShare a Scribd company logo
React Basics
Bill Wolff
phillydotnet.org, inc.
philly.NET labs
• Been doing this for 10 years
• Room gets crowded, arrive early and bring extension cords
• We are not React experts but know enough to get you started
• We are working on live streaming all labs, please be patient!
• Bandwidth is limited at times, keep off the network if possible
• Download key code before you arrive
• This is a community event, please help the person next to you
React Lab Series
• November 8
• React intro, tooling, components, JSX syntax, props, state, lifecycle
• December 6
• React routing, styles, server side render, testing
• January 3
• React flux architecture with Redux and RxJS observables
• February 7
• Make the same simple app in Angular, React, and Vue
• December 20
• Monthly meeting compares Angular, React, and Vue
React
• Maintained by Facebook and Instagram
• Created by Jordan Walke for internal projects
• Initial open source March 2013
• Currently version 16.0.0 as of Sep 2017
• React Native enables phone apps since March 2015
• React Fiber was introduced in 2017
License Controversy
• May 2013 Apache 2.0
• BSD restrictive license followed
• April 2015 updated patent grant
• September 2017 MIT License
Virtual DOM
• Virtual Document Object Model
• In-memory data structure
• React does diff with real DOM and efficiently applies changes
Components
• Implemented as a JavaScript ES6 class
• Extends React.Component
• Render method is required
• JSX is often used in render but not required
• Accept props
• Can maintain state
• ReactDOM.render method creates a DOM instance of a component
JSX
• JavaScript extension syntax
• Nested elements must be wrapped in a single parent
• 16.0.0 allows arrays of elements -> fragments or strings
• Custom attributes require the data- prefix
• Expressions are wrapped in curlies {}
• If/else are not supported but conditional expressions are
One way data flow
• Properties are immutable values passed to render method
• Components should not modify props
• “Properties flow down, actions flow up”
• This architecture is referred to as Flux
• Redux is a popular implementation and will be covered in the January lab
Tooling
• Visual Studio Code
• Node.js with NPM for package management
• Babel and TypeScript transpilers
• Webpack for bundling
• create-react-app for scaffolding
Visual Studio Terminal
• Use terminal mode to run node commands
• Ctrl-`
• Open as many as needed
• Check versions
• node –v
• npm –v
• npm i create-react-app -g
• create-react-app --help
• create-react-app --version
create-react-app
• Depends on react-scripts
• Make an ES6 app
• create-react-app react-app
• Review the file structure and package.json
• Make a TypeScript app
• create-react-app react-app-ts --scripts-version=react-scripts-ts
• Review the file structure and package.json
• /public
• /src
• /node_modules
Test and Build Your Apps
• cd react-app
• npm start
• Use your browser at localhost:3000
• code .
• Opens a new editor for this project folder
• npm run build
• Makes /build folder
• npm install –g serve
• serve –s build
Minimal App
• Remove all files except app.js and index.js
• index.html
• Defines a root element
• index.js
• Renders the App component in the root element
• app.js
• Imports react
• Defines the component class and constructor
• Provides a render method (can use short form stateless function syntax)
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<App />,
document.getElementById('root')
);
app.js – stateless function
import React from 'react';
const App = () => <h1>Go Eagles!</h1>
export default App;
app.js – JSX syntax
import React from 'react';
class App extends React.Component {
render() {
return <h1>Go Eagles!</h1>
}
}
export default App;
app.js – ES6 syntax
import React from 'react';
class App extends React.Component {
render() {
return React.createElement('h1', null, 'Eagles!’)
}
}
export default App;
app.js – single wrapper element
class App extends React.Component {
render() {
return (
<div>
<h1>Go Eagles!</h1>
<h3>beat Dallas</h3>
</div>
);
}
}
Properties
• How static data is passed between components
• propTypes
• Object with keys that define parameter signature
• defaultProps
• Object with keys for default values
app.js – propTypes and defaultTypes
import PropTypes from 'prop-types';
App.propTypes = {
message: PropTypes.string.isRequired,
scoreEagles: PropTypes.number,
scoreCowboys: PropTypes.number
}
App.defaultProps = {
message: "Fly EAGLES Fly"
}
app.js – consuming props
class App extends React.Component {
render() {
let message = this.props.message
return (
<div>
<h1>{message}</h1>
Eagles: {this.props.scoreEagles} - Cowboys:
{this.props.scoreCowboys}
</div>
)
}
}
index.js – sending props
ReactDOM.render(
<App scoreEagles={30} scoreCowboys={17} />,
document.getElementById('root')
);
State
• Properties that will change value
• Call super() in constructor to create context
• Define state object with default values
• Typical to use update() method to change state
• Later we will use lifecycle events to fetch external data to state
App.js – State constructor
constructor(){
super();
this.state = {
message: 'fly eagles fly’,
scoreEagles: 28,
scoreCowboys: 14
}
}
App.js – State update
update(e){
this.setState({message: e.target.value})
}
App.js – State render
render(){
return (
<div>
<input type="text“
onChange={this.update.bind(this)} />
<h1>{this.state.message}</h1>
<h3>Eagles: {this.state.scoreEagles}
- Cowboys: {this.state.scoreCowboys}</h3>
</div>
)
}
App.js – Child component constructor
constructor(){
super();
this.state = {
message: 'Cowboys’
}
}
App.js – Child component update
update(e){
this.setState({message: e.target.value})
}
App.js – Child component render
render(){
return (
<div>
<h1>Who you gonna beat?<br/>
{this.state.message}</h1>
<Cheer update={this.update.bind(this)} /><br/>
<Cheer update={this.update.bind(this)} /><br/>
<Cheer update={this.update.bind(this)} />
</div>
)
}
App.js – Child component
const Cheer = (props) =>
<input type="text" onChange={props.update}/>
App.js – Nested children render
class App extends React.Component {
render(){
return <Button>I <Heart /> the Eagles</Button>
}
}
App.js – Nested child components
const Button = (props) =>
<button>{props.children}</button>
class Heart extends React.Component {
render(){
return <span>&hearts;</span>
}
}
App.js – Synthetic Event constructor
constructor(){
super();
this.state = {currentEvent: '---’}
this.update = this.update.bind(this)
}
update(e){
this.setState({currentEvent: e.type})
}
render(){
return (
<div>
<textarea
onKeyPress={this.update}
onCopy={this.update}
onCut={this.update}
onPaste={this.update}
onFocus={this.update}
onBlur={this.update}
onDoubleClick={this.update}
onTouchStart={this.update}
onTouchMove={this.update}
onTouchEnd={this.update}
cols="30"
rows="10" />
<h1>{this.state.currentEvent}</h1>
</div>
)
}
App.js – Refs constructor
constructor(){
super();
this.state = {a: '', b: ''}
}
update(){
this.setState({
a: this.a.refs.input.value,
b: this.refs.b.value
})
}
App.js – Refs render
render(){
return (
<div>
<Input
ref={ component => this.a = component}
update={this.update.bind(this)}
/> {this.state.a}
<hr />
<input
ref="b"
type="text"
onChange={this.update.bind(this)}
/> {this.state.b}
</div>
)
}
App.js – Refs child component
class Input extends React.Component {
render(){
return <div><input ref="input" type="text“
onChange={this.props.update}/></div>
}
}
Component Lifecycle
• componentWillMount
• componentDidMount
• componentWillUnmount
constructor() {
super();
this.state = {val: 0}
this.update = this.update.bind(this)
}
update(){
this.setState({val: this.state.val + 1})
}
componentWillMount(){
console.log('componentWillMount’)
this.setState({m: 2})
}
render(){
console.log('render’);
return <button onClick={this.update}>
{this.state.val * this.state.m}
</button>
}
componentDidMount() {
console.log('componentDidMount’);
console.log(ReactDOM.findDOMNode(this));
}
// componentDidMount(){
// console.log('componentDidMount');
// this.inc = setInterval(this.update,500)
// }
// componentWillUnmount(){
// console.log('componentWillUnmount')
// clearInterval(this.inc);
// }
Property and State Lifecycle
• componentWillReceiveProps
• shouldComponentUpdate
• componentDidUpdate
constructor(){
super();
this.state = {increasing: false}
}
update(){
ReactDOM.render(
<App val={this.props.val + 1} />,
document.getElementById('root’))
}
componentWillReceiveProps(nextProps){
this.setState({increasing: nextProps.val > this.props.val})
}
shouldComponentUpdate(nextProps, nextState) {
return nextProps.val % 5 === 0;
}
render(){
console.log(this.state.increasing)
return (
<button onClick={this.update.bind(this)}>
{this.props.val}
</button>
)
}
componentDidUpdate(prevProps, prevState) {
console.log(`prevProps: ${prevProps.val}`)
}
App.js – Map data constructor
constructor(){
super();
this.state = {items: []}
}
componentWillMount(){
fetch( 'https://swapi.co/api/people/?format=json’ )
.then( response => response.json() )
.then( ({results: items}) => this.setState({items}))
}
filter(e){
this.setState({filter: e.target.value})
}
App.js – Map data render
render(){
let items = this.state.items;
if(this.state.filter){
items = items.filter( item =>
item.name.toLowerCase()
.includes(this.state.filter.toLowerCase()))
}
return (
<div>
<input type="text"
onChange={this.filter.bind(this)}/>
{items.map(item =>
<Person key={item.name} person={item} />)}
</div>
)
}
App.js – Map data child component
const Person = (props) =>
<h4>{props.person.name}</h4>

More Related Content

What's hot (20)

Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
Yakov Fain
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan Cuprak
 
Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
Talentica Software
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
Talentica Software
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
Mike Slinn
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
Jimit Shah
 
Angular beans
Angular beansAngular beans
Angular beans
Bessem Hmidi
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
Omri Spector
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
Shawn McCool
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1
Jason McCreary
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
Ryan Cuprak
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Stacy London
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
PT.JUG
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web Artisans
Windzoon Technologies
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
Yakov Fain
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
Ryan Cuprak
 
Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
Ryan Cuprak
 
Setting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | TalenticaSetting Up Development Environment For Google App Engine & Python | Talentica
Setting Up Development Environment For Google App Engine & Python | Talentica
Talentica Software
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
Mike Slinn
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
Jimit Shah
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
Omri Spector
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
Darren Craig
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
Shawn McCool
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1
Jason McCreary
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
Ryan Cuprak
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Stacy London
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
PT.JUG
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web Artisans
Windzoon Technologies
 

Similar to 20171108 PDN HOL React Basics (20)

React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
Stacy Goh
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
BOSC Tech Labs
 
Angular or React
Angular or ReactAngular or React
Angular or React
Orkhan Gasimov
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
Ido Flatow
 
Modern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on RailsModern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on Rails
Jonathan Johnson
 
Full Stack_Reac web Development and Application
Full Stack_Reac web Development and ApplicationFull Stack_Reac web Development and Application
Full Stack_Reac web Development and Application
Jeyarajs7
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
Dhaval Barot
 
React js
React jsReact js
React js
Oswald Campesato
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
MskDotNet Community
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
HarshitJain302462
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
HafidzIhzaPratama
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
Codifly
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
Troy Miles
 
Intro react js
Intro react jsIntro react js
Intro react js
Vijayakanth MP
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
500Tech
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
rafaqathussainc077
 
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
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
Mihail Gaberov
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
Jennifer Estrada
 
React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
Stacy Goh
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
BOSC Tech Labs
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
Ido Flatow
 
Modern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on RailsModern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on Rails
Jonathan Johnson
 
Full Stack_Reac web Development and Application
Full Stack_Reac web Development and ApplicationFull Stack_Reac web Development and Application
Full Stack_Reac web Development and Application
Jeyarajs7
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
Dhaval Barot
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
Nitin Tyagi
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
MskDotNet Community
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
Codifly
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
Troy Miles
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
500Tech
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
rafaqathussainc077
 
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
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
Mihail Gaberov
 

Recently uploaded (20)

Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Automation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath CertificateAutomation Techniques in RPA - UiPath Certificate
Automation Techniques in RPA - UiPath Certificate
VICTOR MAESTRE RAMIREZ
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 

20171108 PDN HOL React Basics

  • 2. philly.NET labs • Been doing this for 10 years • Room gets crowded, arrive early and bring extension cords • We are not React experts but know enough to get you started • We are working on live streaming all labs, please be patient! • Bandwidth is limited at times, keep off the network if possible • Download key code before you arrive • This is a community event, please help the person next to you
  • 3. React Lab Series • November 8 • React intro, tooling, components, JSX syntax, props, state, lifecycle • December 6 • React routing, styles, server side render, testing • January 3 • React flux architecture with Redux and RxJS observables • February 7 • Make the same simple app in Angular, React, and Vue • December 20 • Monthly meeting compares Angular, React, and Vue
  • 4. React • Maintained by Facebook and Instagram • Created by Jordan Walke for internal projects • Initial open source March 2013 • Currently version 16.0.0 as of Sep 2017 • React Native enables phone apps since March 2015 • React Fiber was introduced in 2017
  • 5. License Controversy • May 2013 Apache 2.0 • BSD restrictive license followed • April 2015 updated patent grant • September 2017 MIT License
  • 6. Virtual DOM • Virtual Document Object Model • In-memory data structure • React does diff with real DOM and efficiently applies changes
  • 7. Components • Implemented as a JavaScript ES6 class • Extends React.Component • Render method is required • JSX is often used in render but not required • Accept props • Can maintain state • ReactDOM.render method creates a DOM instance of a component
  • 8. JSX • JavaScript extension syntax • Nested elements must be wrapped in a single parent • 16.0.0 allows arrays of elements -> fragments or strings • Custom attributes require the data- prefix • Expressions are wrapped in curlies {} • If/else are not supported but conditional expressions are
  • 9. One way data flow • Properties are immutable values passed to render method • Components should not modify props • “Properties flow down, actions flow up” • This architecture is referred to as Flux • Redux is a popular implementation and will be covered in the January lab
  • 10. Tooling • Visual Studio Code • Node.js with NPM for package management • Babel and TypeScript transpilers • Webpack for bundling • create-react-app for scaffolding
  • 11. Visual Studio Terminal • Use terminal mode to run node commands • Ctrl-` • Open as many as needed • Check versions • node –v • npm –v • npm i create-react-app -g • create-react-app --help • create-react-app --version
  • 12. create-react-app • Depends on react-scripts • Make an ES6 app • create-react-app react-app • Review the file structure and package.json • Make a TypeScript app • create-react-app react-app-ts --scripts-version=react-scripts-ts • Review the file structure and package.json • /public • /src • /node_modules
  • 13. Test and Build Your Apps • cd react-app • npm start • Use your browser at localhost:3000 • code . • Opens a new editor for this project folder • npm run build • Makes /build folder • npm install –g serve • serve –s build
  • 14. Minimal App • Remove all files except app.js and index.js • index.html • Defines a root element • index.js • Renders the App component in the root element • app.js • Imports react • Defines the component class and constructor • Provides a render method (can use short form stateless function syntax)
  • 15. index.js import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; ReactDOM.render( <App />, document.getElementById('root') );
  • 16. app.js – stateless function import React from 'react'; const App = () => <h1>Go Eagles!</h1> export default App;
  • 17. app.js – JSX syntax import React from 'react'; class App extends React.Component { render() { return <h1>Go Eagles!</h1> } } export default App;
  • 18. app.js – ES6 syntax import React from 'react'; class App extends React.Component { render() { return React.createElement('h1', null, 'Eagles!’) } } export default App;
  • 19. app.js – single wrapper element class App extends React.Component { render() { return ( <div> <h1>Go Eagles!</h1> <h3>beat Dallas</h3> </div> ); } }
  • 20. Properties • How static data is passed between components • propTypes • Object with keys that define parameter signature • defaultProps • Object with keys for default values
  • 21. app.js – propTypes and defaultTypes import PropTypes from 'prop-types'; App.propTypes = { message: PropTypes.string.isRequired, scoreEagles: PropTypes.number, scoreCowboys: PropTypes.number } App.defaultProps = { message: "Fly EAGLES Fly" }
  • 22. app.js – consuming props class App extends React.Component { render() { let message = this.props.message return ( <div> <h1>{message}</h1> Eagles: {this.props.scoreEagles} - Cowboys: {this.props.scoreCowboys} </div> ) } }
  • 23. index.js – sending props ReactDOM.render( <App scoreEagles={30} scoreCowboys={17} />, document.getElementById('root') );
  • 24. State • Properties that will change value • Call super() in constructor to create context • Define state object with default values • Typical to use update() method to change state • Later we will use lifecycle events to fetch external data to state
  • 25. App.js – State constructor constructor(){ super(); this.state = { message: 'fly eagles fly’, scoreEagles: 28, scoreCowboys: 14 } }
  • 26. App.js – State update update(e){ this.setState({message: e.target.value}) }
  • 27. App.js – State render render(){ return ( <div> <input type="text“ onChange={this.update.bind(this)} /> <h1>{this.state.message}</h1> <h3>Eagles: {this.state.scoreEagles} - Cowboys: {this.state.scoreCowboys}</h3> </div> ) }
  • 28. App.js – Child component constructor constructor(){ super(); this.state = { message: 'Cowboys’ } }
  • 29. App.js – Child component update update(e){ this.setState({message: e.target.value}) }
  • 30. App.js – Child component render render(){ return ( <div> <h1>Who you gonna beat?<br/> {this.state.message}</h1> <Cheer update={this.update.bind(this)} /><br/> <Cheer update={this.update.bind(this)} /><br/> <Cheer update={this.update.bind(this)} /> </div> ) }
  • 31. App.js – Child component const Cheer = (props) => <input type="text" onChange={props.update}/>
  • 32. App.js – Nested children render class App extends React.Component { render(){ return <Button>I <Heart /> the Eagles</Button> } }
  • 33. App.js – Nested child components const Button = (props) => <button>{props.children}</button> class Heart extends React.Component { render(){ return <span>&hearts;</span> } }
  • 34. App.js – Synthetic Event constructor constructor(){ super(); this.state = {currentEvent: '---’} this.update = this.update.bind(this) } update(e){ this.setState({currentEvent: e.type}) }
  • 36. App.js – Refs constructor constructor(){ super(); this.state = {a: '', b: ''} } update(){ this.setState({ a: this.a.refs.input.value, b: this.refs.b.value }) }
  • 37. App.js – Refs render render(){ return ( <div> <Input ref={ component => this.a = component} update={this.update.bind(this)} /> {this.state.a} <hr /> <input ref="b" type="text" onChange={this.update.bind(this)} /> {this.state.b} </div> ) }
  • 38. App.js – Refs child component class Input extends React.Component { render(){ return <div><input ref="input" type="text“ onChange={this.props.update}/></div> } }
  • 39. Component Lifecycle • componentWillMount • componentDidMount • componentWillUnmount
  • 40. constructor() { super(); this.state = {val: 0} this.update = this.update.bind(this) } update(){ this.setState({val: this.state.val + 1}) } componentWillMount(){ console.log('componentWillMount’) this.setState({m: 2}) }
  • 41. render(){ console.log('render’); return <button onClick={this.update}> {this.state.val * this.state.m} </button> } componentDidMount() { console.log('componentDidMount’); console.log(ReactDOM.findDOMNode(this)); } // componentDidMount(){ // console.log('componentDidMount'); // this.inc = setInterval(this.update,500) // } // componentWillUnmount(){ // console.log('componentWillUnmount') // clearInterval(this.inc); // }
  • 42. Property and State Lifecycle • componentWillReceiveProps • shouldComponentUpdate • componentDidUpdate
  • 43. constructor(){ super(); this.state = {increasing: false} } update(){ ReactDOM.render( <App val={this.props.val + 1} />, document.getElementById('root’)) } componentWillReceiveProps(nextProps){ this.setState({increasing: nextProps.val > this.props.val}) } shouldComponentUpdate(nextProps, nextState) { return nextProps.val % 5 === 0; }
  • 45. App.js – Map data constructor constructor(){ super(); this.state = {items: []} } componentWillMount(){ fetch( 'https://swapi.co/api/people/?format=json’ ) .then( response => response.json() ) .then( ({results: items}) => this.setState({items})) } filter(e){ this.setState({filter: e.target.value}) }
  • 46. App.js – Map data render render(){ let items = this.state.items; if(this.state.filter){ items = items.filter( item => item.name.toLowerCase() .includes(this.state.filter.toLowerCase())) } return ( <div> <input type="text" onChange={this.filter.bind(this)}/> {items.map(item => <Person key={item.name} person={item} />)} </div> ) }
  • 47. App.js – Map data child component const Person = (props) => <h4>{props.person.name}</h4>