SlideShare a Scribd company logo
1 of 39
Download to read offline
React For Dummies
Mitch Chen
Agenda
▸ Components
▸ JSX
▸ Virtual DOM
▸ Rendering
▸ State and Props
▸ Component Lifecycle
▸ Hands-on
▸ Where to go from here
▸ Q & A
Components
▸ Separation of Concerns: Reduce Coupling, increase
Cohesion
▸ Display Logic and Markup are highly Cohesive: They both
show the UI
▸ Components are the right way to separate concerns
▸ Components are Reusable, Composable and Unit Testable
Components
▸ React Components use Expressive power of programming
language(JSX) to build UIs
▸ React Components: A highly Cohesive building block for
UIs Loosely Coupled with other components
▸ React makes you build many simple components that does
one thing really well
Components - Syntax
▸ ES5 Syntax
var	
  MyApp	
  =	
  React.createClass({…});
Components - Syntax
▸ ES6 Syntax
class	
  MyApp	
  extends	
  React.Component	
  {…}
Practice
Hello, world!
http://goo.gl/c7pGK9
Components - Syntax
▸ Stateless Component
These components must not retain internal state,
do not have the component lifecycle methods.
Components - Syntax
▸ Stateless Component - ES5
func.on	
  MyApp(props)	
  {	
  
	
  	
  	
  	
  return	
  <h2>Hello,	
  {props.name}</h2>;	
  
}	
  
ReactDOM.render(	
  
	
  	
  	
  	
  <MyApp	
  name=“Mitch”	
  />,	
  document.getElementById(‘root’)	
  
);
Components - Syntax
▸ Stateless Component - ES6
const	
  MyApp	
  =	
  (props)	
  =>	
  <h2>Hello,	
  {props.name}</h2>;	
  
ReactDOM.render(	
  
	
  	
  	
  	
  <MyApp	
  name=“Mitch”	
  />,	
  document.getElementById(‘root’)	
  
);
JSX
JSX is a JavaScript syntax extension
that looks similar to XML.
JSX
Pure	
  JavaScript:	
  
React.createElement(‘a’,	
  {href:	
  ‘hPps://facebook.github.io/
react/'},	
  ‘Hello!’);	
  
JSX	
  Syntax:	
  
<a	
  href=“hPps://facebook.github.io/react/“>Hello!</a>
JSX
▸ Supported HTML Elements
a abbr address area article aside audio b base bdi bdo big blockquote body br
button canvas caption cite code col colgroup data datalist dd del details dfn
dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5
h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li
link main map mark menu menuitem meta meter nav noscript object ol optgroup
option output p param picture pre progress q rp rt ruby s samp script section
select small source span strong style sub summary sup table tbody td textarea
tfoot th thead time title tr track u ul var video wbr
JSX
▸ Supported HTML Attributes
accept acceptCharset accessKey action allowFullScreen allowTransparency alt
async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge
charSet checked cite classID className colSpan cols content contentEditable
contextMenu controls coords crossOrigin data dateTime default defer dir
disabled download draggable encType form formAction formEncType formMethod
formNoValidate formTarget frameBorder headers height hidden high href hrefLang
htmlFor httpEquiv icon id inputMode integrity is keyParams keyType kind label
lang list loop low manifest marginHeight marginWidth max maxLength media
mediaGroup method min minLength multiple muted name noValidate nonce open
optimum pattern placeholder poster preload profile radioGroup readOnly rel
required reversed role rowSpan rows sandbox scope scoped scrolling seamless
selected shape size sizes span spellCheck src srcDoc srcLang srcSet start step
style summary tabIndex target title type useMap value width wmode wrap
JSX
▸ Event System
▸ DOM Differences
▸ Special Non-DOM Attributes
Virtual Dom
▸ Makes re-rendering on every change fast
▸ Computes minimal DOM operations
▸ Batched reads and writes for optimal DOM performance
▸ Usually faster than manual DOM operations
▸ 60fps, even in a UIWebView on the iPhone
Virtual Dom
A ReactElement is a light, stateless, immutable,
virtual representation of a DOM Element. It is
a virtual DOM
Rendering
▸ State has data you own, Props has data you borrow
▸ When the State(data) changes, React Re-renders the Entire
Component
▸ No magical data binding
▸ No model dirty checking
▸ No more explicit DOM operations: Everything is
declarative
Rendering
setState Dirty
Batching
Rendering
Dirty
Sub-tree Rendering
Re-Rendered
State And Props
▸ State is mutable
▸ State is private to the component
▸ State can be changed by calling this.setState()
▸ When the state updates, the component re-renders itself
State And Props
▸ Props are immutable
▸ Based on its props, each component has rendered itself
once
▸ Props are passed from the parent
▸ Props are owned by the parent
State And Props
▸ Prop Validation
class	
  MyApp	
  extends	
  React.Component	
  {…}	
  
MyApp.propTypes	
  =	
  {	
  
	
  	
  	
  	
  opVonalArray:	
  React.PropTypes.array,	
  
	
  	
  	
  	
  opVonalBool:	
  React.PropTypes.bool,	
  
	
  	
  	
  	
  opVonalFunc:	
  React.PropTypes.func,	
  
	
  	
  	
  	
  opVonalNumber:	
  React.PropTypes.number,	
  
	
  	
  	
  	
  opVonalObject:	
  React.PropTypes.object,	
  
	
  	
  	
  	
  opVonalString:	
  React.PropTypes.string,	
  
	
  	
  	
  	
  opVonalNode:	
  React.PropTypes.node,	
  
	
  	
  	
  	
  opVonalElement:	
  React.PropTypes.element	
  
};
State And Props
▸ Prop Validation
class	
  MyApp	
  extends	
  React.Component	
  {…}	
  
MyApp.propTypes	
  =	
  {	
  
	
  	
  	
  	
  opVonalMessage:	
  React.PropTypes.instanceOf(Message),	
  
	
  	
  	
  	
  opVonalEnum:	
  React.PropTypes.oneOf([‘News’,	
  ‘Photos’]),	
  
	
  	
  	
  	
  opVonalUnion:	
  React.PropTypes.oneOfType([	
  
	
  	
  	
  	
  	
  	
  	
  	
  React.PropTypes.number,	
  
	
  	
  	
  	
  	
  	
  	
  	
  React.PropTypes.string	
  
	
  	
  	
  	
  ]),	
  
	
  	
  	
  	
  opVonalArrayOf:	
  React.PropTypes.arrayOf(React.PropTypes.number),	
  
	
  	
  	
  	
  opVonalObjectOf:	
  React.PropTypes.objectOf(React.PropTypes.number)	
  
};
State And Props
▸ Prop Validation
class	
  MyApp	
  extends	
  React.Component	
  {…}	
  
MyApp.propTypes	
  =	
  {	
  
	
  	
  	
  	
  opVonalObjectWithShape:	
  React.PropTypes.shape({	
  
	
  	
  	
  	
  	
  	
  	
  	
  name:	
  React.PropTypes.string,	
  
	
  	
  	
  	
  	
  	
  	
  	
  count:	
  React.PropTypes.number	
  
	
  	
  	
  	
  }),	
  
	
  	
  	
  	
  requiredFunc:	
  React.PropTypes.func.isRequired,	
  
	
  	
  	
  	
  requiredAny:	
  React.PropTypes.any.isRequired	
  
};
State And Props
▸ Dumb Components
- The most reusable components available
- They have a know-nothing approach to the
application in which they are used.
- It does not connect to any Flux interfaces, and is
passed the exact data it needs to render (via Props).
Practice
NavBar Component
http://codepen.io/mitchbox/pen/
ZOAWqk
Practice
ProfileCard Component
http://codepen.io/mitchbox/pen/
GqQkwE
State And Props
▸ Smart Components
- Less reusable outside a single application or set of
applications
- They are aware of application-level state.
- It may bind to Flux actions or stores in order to
directly integrate with business logic and react to
changes.
Practice
Click and count
http://codepen.io/mitchbox/pen/
mEXPaw
▸ Changing props and state
State And Props
- Props State
Can get initial value from parent Component? Y Y
Can be changed by parent Component? Y N
Can set default values inside Component? Y Y
Can change inside Component? N Y
Can set initial value for child Components? Y Y
Can change in child Components? Y N
Component Lifecycle Methods
▸ componentWillMount
▸ componentDidMount
▸ componentWillReceiveProps
▸ componentWillUnmount
▸ shouldComponentUpdate
▸ componentWillUpdate
▸ componentDidUpdate
▸ Search Github User (Integrate with Github API)
Hands-On
Github API
https://api.github.com/users/{username}
▸ Search Github User (Integrate with Github API)
Hands-On
- Include NavBar and ProfileCard components
- Implement API helper function
- Create an App Container Component
- Add event handler and call Github API
- State management
- UI Rendering with state
- http://codepen.io/mitchbox/pen/bZLpOr
Where To Go From Here
▸ Development Environment & Tools
▸ Basic Technical Skill Requirements
▸ Familiar with React Related Third Party Libraries
▸ Familiar with Migo Internal Libraries and Boilerplate
Where To Go From Here
▸ Development Environment & Tools
- Node.js / NPM
- Webpack / Gulp / Grunt
- Babel (JavaScript Compiler)
- Live Reload
- ESLint
- Mocha / Chai
Where To Go From Here
▸ Basic Technical Skill Requirements
- CSS / CSS 3 / SASS / (PostCSS)
- Naming Convention for CSS (BEM)
- Coding Convention for React
- ECMAScript 2015 aka ES6
- Functional Programming
Where To Go From Here
▸ Familiar with React Related Third Party Libraries
- Flux
- ReFlux
- Redux
- Redux Thunk
- Redux Middleware
- React-router
- Classnames
- Immutable.js
- Flow
Q & A

More Related Content

What's hot

[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 

What's hot (20)

[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
React web development
React web developmentReact web development
React web development
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
Reactjs
Reactjs Reactjs
Reactjs
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
ReactJs
ReactJsReactJs
ReactJs
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
React JS part 1
React JS part 1React JS part 1
React JS part 1
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
React workshop
React workshopReact workshop
React workshop
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
 

Viewers also liked

Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 
Engine de template em Javascript com HTML Sprites
Engine de template em Javascript com HTML SpritesEngine de template em Javascript com HTML Sprites
Engine de template em Javascript com HTML Sprites
Milfont Consulting
 

Viewers also liked (12)

React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
React js
React jsReact js
React js
 
Redis tutoring
Redis tutoringRedis tutoring
Redis tutoring
 
React-js
React-jsReact-js
React-js
 
React.js
React.jsReact.js
React.js
 
React.js for Back-End developers
React.js for Back-End developersReact.js for Back-End developers
React.js for Back-End developers
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
React.js in real world apps.
React.js in real world apps. React.js in real world apps.
React.js in real world apps.
 
React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Engine de template em Javascript com HTML Sprites
Engine de template em Javascript com HTML SpritesEngine de template em Javascript com HTML Sprites
Engine de template em Javascript com HTML Sprites
 

Similar to React for Dummies

Similar to React for Dummies (20)

Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
 
Lec7Handout.ppt
Lec7Handout.pptLec7Handout.ppt
Lec7Handout.ppt
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
ReactJS
ReactJSReactJS
ReactJS
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Workshop 19: ReactJS Introduction
Workshop 19: ReactJS IntroductionWorkshop 19: ReactJS Introduction
Workshop 19: ReactJS Introduction
 
Purifying React (with annotations)
Purifying React (with annotations)Purifying React (with annotations)
Purifying React (with annotations)
 
React native
React nativeReact native
React native
 
ReactJS (1)
ReactJS (1)ReactJS (1)
ReactJS (1)
 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - React
 
A React Journey
A React JourneyA React Journey
A React Journey
 
React, Flux and more (p1)
React, Flux and more (p1)React, Flux and more (p1)
React, Flux and more (p1)
 
React
ReactReact
React
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 

React for Dummies

  • 2. Agenda ▸ Components ▸ JSX ▸ Virtual DOM ▸ Rendering ▸ State and Props ▸ Component Lifecycle ▸ Hands-on ▸ Where to go from here ▸ Q & A
  • 3. Components ▸ Separation of Concerns: Reduce Coupling, increase Cohesion ▸ Display Logic and Markup are highly Cohesive: They both show the UI ▸ Components are the right way to separate concerns ▸ Components are Reusable, Composable and Unit Testable
  • 4. Components ▸ React Components use Expressive power of programming language(JSX) to build UIs ▸ React Components: A highly Cohesive building block for UIs Loosely Coupled with other components ▸ React makes you build many simple components that does one thing really well
  • 5. Components - Syntax ▸ ES5 Syntax var  MyApp  =  React.createClass({…});
  • 6. Components - Syntax ▸ ES6 Syntax class  MyApp  extends  React.Component  {…}
  • 8. Components - Syntax ▸ Stateless Component These components must not retain internal state, do not have the component lifecycle methods.
  • 9. Components - Syntax ▸ Stateless Component - ES5 func.on  MyApp(props)  {          return  <h2>Hello,  {props.name}</h2>;   }   ReactDOM.render(          <MyApp  name=“Mitch”  />,  document.getElementById(‘root’)   );
  • 10. Components - Syntax ▸ Stateless Component - ES6 const  MyApp  =  (props)  =>  <h2>Hello,  {props.name}</h2>;   ReactDOM.render(          <MyApp  name=“Mitch”  />,  document.getElementById(‘root’)   );
  • 11. JSX JSX is a JavaScript syntax extension that looks similar to XML.
  • 12. JSX Pure  JavaScript:   React.createElement(‘a’,  {href:  ‘hPps://facebook.github.io/ react/'},  ‘Hello!’);   JSX  Syntax:   <a  href=“hPps://facebook.github.io/react/“>Hello!</a>
  • 13. JSX ▸ Supported HTML Elements a abbr address area article aside audio b base bdi bdo big blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td textarea tfoot th thead time title tr track u ul var video wbr
  • 14. JSX ▸ Supported HTML Attributes accept acceptCharset accessKey action allowFullScreen allowTransparency alt async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge charSet checked cite classID className colSpan cols content contentEditable contextMenu controls coords crossOrigin data dateTime default defer dir disabled download draggable encType form formAction formEncType formMethod formNoValidate formTarget frameBorder headers height hidden high href hrefLang htmlFor httpEquiv icon id inputMode integrity is keyParams keyType kind label lang list loop low manifest marginHeight marginWidth max maxLength media mediaGroup method min minLength multiple muted name noValidate nonce open optimum pattern placeholder poster preload profile radioGroup readOnly rel required reversed role rowSpan rows sandbox scope scoped scrolling seamless selected shape size sizes span spellCheck src srcDoc srcLang srcSet start step style summary tabIndex target title type useMap value width wmode wrap
  • 15. JSX ▸ Event System ▸ DOM Differences ▸ Special Non-DOM Attributes
  • 16. Virtual Dom ▸ Makes re-rendering on every change fast ▸ Computes minimal DOM operations ▸ Batched reads and writes for optimal DOM performance ▸ Usually faster than manual DOM operations ▸ 60fps, even in a UIWebView on the iPhone
  • 17. Virtual Dom A ReactElement is a light, stateless, immutable, virtual representation of a DOM Element. It is a virtual DOM
  • 18. Rendering ▸ State has data you own, Props has data you borrow ▸ When the State(data) changes, React Re-renders the Entire Component ▸ No magical data binding ▸ No model dirty checking ▸ No more explicit DOM operations: Everything is declarative
  • 21. State And Props ▸ State is mutable ▸ State is private to the component ▸ State can be changed by calling this.setState() ▸ When the state updates, the component re-renders itself
  • 22. State And Props ▸ Props are immutable ▸ Based on its props, each component has rendered itself once ▸ Props are passed from the parent ▸ Props are owned by the parent
  • 23. State And Props ▸ Prop Validation class  MyApp  extends  React.Component  {…}   MyApp.propTypes  =  {          opVonalArray:  React.PropTypes.array,          opVonalBool:  React.PropTypes.bool,          opVonalFunc:  React.PropTypes.func,          opVonalNumber:  React.PropTypes.number,          opVonalObject:  React.PropTypes.object,          opVonalString:  React.PropTypes.string,          opVonalNode:  React.PropTypes.node,          opVonalElement:  React.PropTypes.element   };
  • 24. State And Props ▸ Prop Validation class  MyApp  extends  React.Component  {…}   MyApp.propTypes  =  {          opVonalMessage:  React.PropTypes.instanceOf(Message),          opVonalEnum:  React.PropTypes.oneOf([‘News’,  ‘Photos’]),          opVonalUnion:  React.PropTypes.oneOfType([                  React.PropTypes.number,                  React.PropTypes.string          ]),          opVonalArrayOf:  React.PropTypes.arrayOf(React.PropTypes.number),          opVonalObjectOf:  React.PropTypes.objectOf(React.PropTypes.number)   };
  • 25. State And Props ▸ Prop Validation class  MyApp  extends  React.Component  {…}   MyApp.propTypes  =  {          opVonalObjectWithShape:  React.PropTypes.shape({                  name:  React.PropTypes.string,                  count:  React.PropTypes.number          }),          requiredFunc:  React.PropTypes.func.isRequired,          requiredAny:  React.PropTypes.any.isRequired   };
  • 26. State And Props ▸ Dumb Components - The most reusable components available - They have a know-nothing approach to the application in which they are used. - It does not connect to any Flux interfaces, and is passed the exact data it needs to render (via Props).
  • 29. State And Props ▸ Smart Components - Less reusable outside a single application or set of applications - They are aware of application-level state. - It may bind to Flux actions or stores in order to directly integrate with business logic and react to changes.
  • 31. ▸ Changing props and state State And Props - Props State Can get initial value from parent Component? Y Y Can be changed by parent Component? Y N Can set default values inside Component? Y Y Can change inside Component? N Y Can set initial value for child Components? Y Y Can change in child Components? Y N
  • 32. Component Lifecycle Methods ▸ componentWillMount ▸ componentDidMount ▸ componentWillReceiveProps ▸ componentWillUnmount ▸ shouldComponentUpdate ▸ componentWillUpdate ▸ componentDidUpdate
  • 33. ▸ Search Github User (Integrate with Github API) Hands-On Github API https://api.github.com/users/{username}
  • 34. ▸ Search Github User (Integrate with Github API) Hands-On - Include NavBar and ProfileCard components - Implement API helper function - Create an App Container Component - Add event handler and call Github API - State management - UI Rendering with state - http://codepen.io/mitchbox/pen/bZLpOr
  • 35. Where To Go From Here ▸ Development Environment & Tools ▸ Basic Technical Skill Requirements ▸ Familiar with React Related Third Party Libraries ▸ Familiar with Migo Internal Libraries and Boilerplate
  • 36. Where To Go From Here ▸ Development Environment & Tools - Node.js / NPM - Webpack / Gulp / Grunt - Babel (JavaScript Compiler) - Live Reload - ESLint - Mocha / Chai
  • 37. Where To Go From Here ▸ Basic Technical Skill Requirements - CSS / CSS 3 / SASS / (PostCSS) - Naming Convention for CSS (BEM) - Coding Convention for React - ECMAScript 2015 aka ES6 - Functional Programming
  • 38. Where To Go From Here ▸ Familiar with React Related Third Party Libraries - Flux - ReFlux - Redux - Redux Thunk - Redux Middleware - React-router - Classnames - Immutable.js - Flow
  • 39. Q & A