SlideShare uma empresa Scribd logo
1 de 47
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>

Mais conteúdo relacionado

Mais procurados

Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developersYakov Fain
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan 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 | TalenticaTalentica Software
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike 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 DOMJimit 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 BootOmri Spector
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with SeleniumAll 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 ArchitectureShawn McCool
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1Jason McCreary
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan 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 DataStacy London
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkPT.JUG
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with ArquillianIvan 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 ArtisansWindzoon Technologies
 

Mais procurados (20)

Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)Why jakarta ee matters (ConFoo 2021)
Why jakarta ee matters (ConFoo 2021)
 
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
 
Test Policy and Practices
Test Policy and PracticesTest Policy and Practices
Test Policy and Practices
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
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
 
Angular beans
Angular beansAngular beans
Angular beans
 
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
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
 
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
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
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
 
An Introduction to Play 2 Framework
An Introduction to Play 2 FrameworkAn Introduction to Play 2 Framework
An Introduction to Play 2 Framework
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
 
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
 

Semelhante a 20171108 PDN HOL React Basics

React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshopStacy 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 jsBOSC Tech Labs
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0Ido 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 RailsJonathan Johnson
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React nativeDhaval 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 & WebpackCodifly
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN StackTroy 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 comparison500Tech
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basicrafaqathussainc077
 
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 APIsMihail Gaberov
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSPratik Majumdar
 

Semelhante a 20171108 PDN HOL React Basics (20)

React && React Native workshop
React && React Native workshopReact && React Native workshop
React && React Native workshop
 
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
 
Angular or React
Angular or ReactAngular or React
Angular or React
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
 
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
 
Introduction to React native
Introduction to React nativeIntroduction to React native
Introduction to React native
 
React js
React jsReact js
React js
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
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
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Intro react js
Intro react jsIntro react js
Intro react js
 
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
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
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]
 
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
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
 

Último

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
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
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.
 
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
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Último (20)

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 ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
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 ...
 
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 ☂️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

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>