SlideShare a Scribd company logo
1 / 34
Starter Kit Basic Examples
React Examples
Eueung Mulyana
https://eueung.github.io/112016/react-cont
CodeLabs | Attribution-ShareAlike CC BY-SA
React Version: 15.4.1
Introduction to React already covered here: https://eueung.github.io/112016/react
2 / 34
3 / 34
React Releases
@github
Outline
Starter Kit - Overview
Basic Examples
4 / 34
Starter Kit Overview
5 / 34
6 / 34
Structure
react-15.4.1$tree-L2
.
|--build
|------react-dom-fiber.js
| |--react-dom-fiber.min.js
| |--react-dom.js
| |--react-dom.min.js
| |--react-dom-server.js
| |--react-dom-server.min.js
| |--react.js
| |--react.min.js
| |--react-with-addons.js
| |--react-with-addons.min.js
|--examples
| |--basic
| |--basic-click-counter
| |--basic-commonjs
| |--basic-jsx
| |--basic-jsx-external
| |--basic-jsx-harmony
| |--basic-jsx-precompile
| |--fiber
| |--jquery-bootstrap
| |--jquery-mobile
| |--quadratic
| |--README.md
| |--shared
| |--transitions
| |--webcomponents
|--README.md
Basic Examples
7 / 34
8 / 34
Basic Examples
One HTML
basic
basic-jsx
basic-jsx-harmony
basic-click-counter (state)
ber (react-dom- ber)
One HTML + One JS
basic-jsx-external (src/example.js)
basic-jsx-precompile (build/example.js)
HTML+JS+package.json (npm)
basic-commonjs (bundle.js)
9 / 34
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<title>BasicExample</title>
<linkrel="stylesheet"href="../shared/css/base.css"/>
</head>
<body>
<h1>BasicExample</h1>
<divid="container">
<p>ToinstallReact,followtheinstructionson<ahref="https://github.com/facebook/react/"
<p>Ifyoucanseethis,Reactis<strong>not</strong>workingright.IfyoucheckedoutthesourcefromGitHubmakesuretorun
</div>
<h4>ExampleDetails</h4>
<p>ThisiswritteninvanillaJavaScript(withoutJSX)andtransformedinthebrowser.</p>
<p>
LearnmoreaboutReactat<ahref="https://facebook.github.io/react"target="_blank">facebook.github.io/react
</p>
<scriptsrc="../../build/react.js"></script>
<scriptsrc="../../build/react-dom.js"></script>
<script>...</script>
</body>
</html>
HTML
basic
basic-jsx
basic-jsx-harmony
ber
basic-click-counter
10 / 34
<script>
varExampleApplication=React.createClass({
render:function(){
varelapsed=Math.round(this.props.elapsed /100);
varseconds=elapsed/10+(elapsed%10?'':'.0');
varmessage=
'Reacthasbeensuccessfullyrunningfor'+seconds+'seconds.';
returnReact.DOM.p(null,message);
}
});
//CallReact.createFactoryinsteadofdirectlycallExampleApplication({...})inReact.render
varExampleApplicationFactory=React.createFactory(ExampleApplication);
varstart=newDate().getTime();
setInterval(function(){
ReactDOM.render(
ExampleApplicationFactory({elapsed:newDate().getTime()-start}),
document.getElementById('container')
);
},50);
</script>
basic
Vanilla JS
render
this.props
React.DOM.p()
11 / 34
<p>ThisiswrittenwithJSXandtransformedinthebrowser.</p>
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
<scripttype="text/babel">
varExampleApplication=React.createClass({
render:function(){
varelapsed=Math.round(this.props.elapsed /100);
varseconds=elapsed/10+(elapsed%10?'':'.0');
varmessage=
'Reacthasbeensuccessfullyrunningfor'+seconds+'seconds.';
return<p>{message}</p>;
}
});
varstart=newDate().getTime();
setInterval(function(){
ReactDOM.render(
<ExampleApplicationelapsed={newDate().getTime()-start}/>,
document.getElementById('container')
);
},50);
</script>
basic-jsx
JS+JSX
Requires babel
render
this.props
Element <p>
Passing props.elapsed
12 / 34
<p>ThisiswrittenwithJSXwithHarmony(ES6)syntaxandtransformedinthebrowser.</p>
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
<scripttype="text/babel">
classExampleApplicationextendsReact.Component{
render(){
varelapsed=Math.round(this.props.elapsed /100);
varseconds=elapsed/10+(elapsed%10?'':'.0');
varmessage=
`Reacthasbeensuccessfullyrunningfor${seconds}seconds.`;
return<p>{message}</p>;
}
}
varstart=newDate().getTime();
setInterval(()=>{
ReactDOM.render(
<ExampleApplicationelapsed={newDate().getTime()-start}/>,
document.getElementById('container')
);
},50);
</script>
basic-jsx-
harmony
ES2015+JSX
Requires babel
render
this.props
Element <p>
13 / 34
basic
14 / 34
basic-jsx
15 / 34
basic-jsx-
harmony
16 / 34
<scriptsrc="../../build/react-dom-fiber.js"></script>
<script>
functionExampleApplication(props){
varelapsed=Math.round(props.elapsed /100);
varseconds=elapsed/10+(elapsed%10?'':'.0');
varmessage=
'Reacthasbeensuccessfullyrunningfor'+seconds+'seconds.';
returnReact.DOM.p(null,message);
}
//CallReact.createFactoryinsteadofdirectlycallExampleApplication({...})inReact.render
varExampleApplicationFactory=React.createFactory(ExampleApplication);
varstart=newDate().getTime();
setInterval(function(){
ReactDOMFiber.render(
ExampleApplicationFactory({elapsed:newDate().getTime()-start}),
document.getElementById('container')
);
},50);
</script>
fiber
basic with ber
function vs. React.createClass()
ReactDOMFiber vs. ReactDOM
Ref: React Fiber is an ongoing
reimplementation of React's core
algorithm. It is the culmination of over
two years of research by the React team.
[ React Fiber ]
17 / 34
fiber
18 / 34
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
<scripttype="text/babel">
varCounter=React.createClass({
getInitialState:function(){
return{count:0};
},
handleClick:function(){
this.setState({
count:this.state.count+1,
});
},
render:function(){
return(
<buttononClick={this.handleClick}>
Clickme!Numberofclicks:{this.state.count}
</button>
);
}
});
ReactDOM.render(
<Counter/>,
document.getElementById('container')
);
</script>
basic-click-
counter
JS+JSX
Requires babel
this.state
this.setState
getInitialState
render
19 / 34
basic-click-
counter
20 / 34
basic-jsx-
external
JS+JSX
Requires babel
basic-jsx
index.html
example.js
<scripttype="text/babel"src="example.js"></script>
21 / 34
basic-jsx-
external
22 / 34
basic-jsx-
external
react-15.4.1$python-mSimpleHTTPServer
ServingHTTPon0.0.0.0port8000...
127.0.0.1--[04/Dec/201603:28:06]"GET/examples/basic-jsx-external/HTTP/1.1"200-
127.0.0.1--[04/Dec/201603:28:06]"GET/examples/shared/css/base.cssHTTP/1.1"200-
127.0.0.1--[04/Dec/201603:28:06]"GET/build/react.jsHTTP/1.1"200-
127.0.0.1--[04/Dec/201603:28:06]"GET/build/react-dom.jsHTTP/1.1"200-
127.0.0.1--[04/Dec/201603:28:06]"GET/examples/basic-jsx-external/example.jsHTTP/1.1"200-
23 / 34
basic-jsx-
precompile
JS+JSX
babel @dev NOT @browser
basic-jsx
index.html
example.js
<scriptsrc="build/example.js"></script>
24 / 34
basic-jsx-
precompile
$npminstall-gbabel-cli
$npminstall-gbabel-preset-react
$npminstall-gbabel-preset-es2015
$babelversion
6.18.0(babel-core6.18.2)
$babel--presetsreactexample.js--out-dir=build
example.js->buildexample.js
react-15.4.1/examples/basic-jsx-precompile$tree
.
|--example.js
|--index.html
|--build
|---example.js
25 / 34
basic-jsx-
precompile
Vanilla JS after Build
Testing: HTTP Server NOT Required
26 / 34
basic-
commonjs
JS+JSX
react & babel @dev NOT
@browser
basic-jsx
index.html
index.js
package.json
<scriptsrc="bundle.js"></script>
27 / 34
basic-
commonjs
index.html
index.js
<!DOCTYPEhtml>
<html>
<head>...</head>
<body>
<h1>BasicCommonJSExamplewithBrowserify</h1>
<divid="container"><p>ToinstallReact,...</p></div>
<h4>ExampleDetails</h4><p>Thisiswritten...</p>
<scriptsrc="bundle.js"></script>
</body>
</html>
'usestrict';
varReact=require('react');
varReactDOM=require('react-dom');
varExampleApplication=React.createClass({
render:function(){
varelapsed=Math.round(this.props.elapsed /100);
varseconds=elapsed/10+(elapsed%10?'':'.0');
varmessage=
'Reacthasbeensuccessfullyrunningfor'+seconds+'seconds.';
return<p>{message}</p>;
}
});
...
28 / 34
basic-
commonjs
package.json
{
"name":"react-basic-commonjs-example",
"description":"BasicexampleofusingReactwithCommonJS",
"private":true,
"main":"index.js",
"dependencies":{
"babel-preset-es2015":"^6.6.0",
"babel-preset-react":"^6.5.0",
"babelify":"^7.3.0",
"browserify":"^13.0.0",
"react":"^15.0.2",
"react-dom":"^15.0.2",
"watchify":"^3.7.0"
},
"scripts":{
"build":"browserify./index.js-tbabelify-obundle.js",
"start":"watchify./index.js-v-tbabelify-obundle.js"
}
}
29 / 34
basic-
commonjs
basic-commonjs$npminstall
basic-commonjs$npmstart
>react-basic-commonjs-example@start/home/em/basic-commonjs
>watchify./index.js-v-tbabelify-obundle.js
721641byteswrittentobundle.js(2.18seconds)
basic-commonjs$tree-L1
.
|--bundle.js
|--index.html
|--index.js
|--node_modules
|--package.json
30 / 34
basic-
commonjs
Vanilla JS after Build
Everything Bundled
Testing: HTTP Server NOT Required
31 / 34
That's All
for the basics ...
we'll continue
later ... piece of
cake, no?
Refs
32 / 34
Refs
1. A JavaScript library for building user interfaces | React
2. facebook/react: A declarative, e cient, and exible JavaScript library for building user
interfaces.
3. acdlite/react- ber-architecture: A description of React's new core algorithm, React Fiber
4. Intro and Concept - Learning React
33 / 34
34 / 34
END
Eueung Mulyana
https://eueung.github.io/112016/react-cont
CodeLabs | Attribution-ShareAlike CC BY-SA

More Related Content

PDF
React Example + Bootstrap
PDF
(Declarative) Jenkins Pipelines
PDF
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
PDF
Getting Started with EasyBuild - Tutorial Part 2
PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PPTX
Virtual Bolt Workshop - March 16, 2020
PDF
JavaOne 2016 - Pipeline as code
PPTX
Docker - BWI Innovation Talk
React Example + Bootstrap
(Declarative) Jenkins Pipelines
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Getting Started with EasyBuild - Tutorial Part 2
Dependencies Managers in C/C++. Using stdcpp 2014
Virtual Bolt Workshop - March 16, 2020
JavaOne 2016 - Pipeline as code
Docker - BWI Innovation Talk

What's hot (13)

PDF
Automate Your Automation | DrupalCon Vienna
PPTX
Large scale automation with jenkins
PDF
TYPO3 Flow 2.0 in the field - webtech Conference 2013
PPTX
Pipeline as code - new feature in Jenkins 2
PPTX
Contributing to OpenStack
PDF
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
PDF
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
PDF
Virtual Bolt Workshop, 5 May 2020
ODP
Migrating to Git: Rethinking the Commit
PPTX
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
PPTX
Jenkins days workshop pipelines - Eric Long
PDF
7 Habits of Highly Effective Jenkins Users
PPTX
Custom Buildpacks and Data Services
Automate Your Automation | DrupalCon Vienna
Large scale automation with jenkins
TYPO3 Flow 2.0 in the field - webtech Conference 2013
Pipeline as code - new feature in Jenkins 2
Contributing to OpenStack
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
Virtual Bolt Workshop, 5 May 2020
Migrating to Git: Rethinking the Commit
Easily Manage Patching and Application Updates with Chocolatey + Puppet - Apr...
Jenkins days workshop pipelines - Eric Long
7 Habits of Highly Effective Jenkins Users
Custom Buildpacks and Data Services
Ad

Similar to React Basic Examples (20)

PDF
Webpack: from 0 to 2
PPTX
Lecture05.pptx
PDF
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
PDF
Assign, Commit, and Review
PPTX
CISOA Conference 2020 Banner 9 Development
PPTX
Bot or not? Detecting bots in GitHub pull request activity based on comment s...
PDF
Open shift deployment review getting ready for day 2 operations
PDF
DWX 2022 - DevSecOps mit GitHub
PDF
PDF
Intro to Pinax: Kickstarting Your Django Apps
PDF
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
PDF
10 tips for Redux at scale
PDF
Redux at scale
PPTX
PPTX
Git & GitHub
PDF
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
PDF
Intro to Github Actions @likecoin
PDF
Rntb20200325
 
PPTX
Cycle.js a reactive framework
PPTX
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Webpack: from 0 to 2
Lecture05.pptx
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, Commit, and Review
CISOA Conference 2020 Banner 9 Development
Bot or not? Detecting bots in GitHub pull request activity based on comment s...
Open shift deployment review getting ready for day 2 operations
DWX 2022 - DevSecOps mit GitHub
Intro to Pinax: Kickstarting Your Django Apps
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
10 tips for Redux at scale
Redux at scale
Git & GitHub
PyCon JP 2024 Streamlining Testing in a Large Python Codebase .pdf
Intro to Github Actions @likecoin
Rntb20200325
 
Cycle.js a reactive framework
Continuous integration / continuous delivery of web applications, Eugen Kuzmi...
Ad

More from Eueung Mulyana (20)

PDF
FGD Big Data
PDF
Hyper-Connectivity and Data Proliferation - Ecosystem Perspective
PDF
Industry 4.0 And Beyond The A.I* For Surviving A Tech-Accelerated World
PDF
Blockchain Introduction
PDF
Bringing Automation to the Classroom: A ChatOps-Based Approach
PDF
FinTech & Cryptocurrency Introduction
PDF
Open Source Networking Overview
PDF
ONOS SDN Controller - Clustering Tests & Experiments
PDF
Open stack pike-devstack-tutorial
PDF
Basic onos-tutorial
PDF
ONOS SDN Controller - Introduction
PDF
OpenDaylight SDN Controller - Introduction
PDF
Mininet Basics
PDF
Android Programming Basics
PDF
Cloud Computing: Overview and Examples
PDF
selected input/output - sensors and actuators
PDF
Connected Things, IoT and 5G
PDF
Connectivity for Local Sensors and Actuators Using nRF24L01+
PDF
NodeMCU with Blynk and Firebase
PDF
Trends and Enablers - Connected Services and Cloud Computing
FGD Big Data
Hyper-Connectivity and Data Proliferation - Ecosystem Perspective
Industry 4.0 And Beyond The A.I* For Surviving A Tech-Accelerated World
Blockchain Introduction
Bringing Automation to the Classroom: A ChatOps-Based Approach
FinTech & Cryptocurrency Introduction
Open Source Networking Overview
ONOS SDN Controller - Clustering Tests & Experiments
Open stack pike-devstack-tutorial
Basic onos-tutorial
ONOS SDN Controller - Introduction
OpenDaylight SDN Controller - Introduction
Mininet Basics
Android Programming Basics
Cloud Computing: Overview and Examples
selected input/output - sensors and actuators
Connected Things, IoT and 5G
Connectivity for Local Sensors and Actuators Using nRF24L01+
NodeMCU with Blynk and Firebase
Trends and Enablers - Connected Services and Cloud Computing

Recently uploaded (20)

PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
Digital Literacy And Online Safety on internet
PPT
tcp ip networks nd ip layering assotred slides
PPTX
artificialintelligenceai1-copy-210604123353.pptx
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
DOCX
Unit-3 cyber security network security of internet system
PPTX
E -tech empowerment technologies PowerPoint
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
Mathew Digital SEO Checklist Guidlines 2025
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
Introuction about ICD -10 and ICD-11 PPT.pptx
SASE Traffic Flow - ZTNA Connector-1.pdf
Digital Literacy And Online Safety on internet
tcp ip networks nd ip layering assotred slides
artificialintelligenceai1-copy-210604123353.pptx
Exploring VPS Hosting Trends for SMBs in 2025
Slides PPTX World Game (s) Eco Economic Epochs.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
introduction about ICD -10 & ICD-11 ppt.pptx
Module 1 - Cyber Law and Ethics 101.pptx
Introuction about WHO-FIC in ICD-10.pptx
An introduction to the IFRS (ISSB) Stndards.pdf
Unit-3 cyber security network security of internet system
E -tech empowerment technologies PowerPoint
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Mathew Digital SEO Checklist Guidlines 2025
Power Point - Lesson 3_2.pptx grad school presentation
Sims 4 Historia para lo sims 4 para jugar
Cloud-Scale Log Monitoring _ Datadog.pdf

React Basic Examples