SlideShare a Scribd company logo
1© 2018 Rogue Wave Software, Inc. All Rights Reserved.
2© 2018 Rogue Wave Software, Inc. All Rights Reserved.
3© 2018 Rogue Wave Software, Inc. All Rights Reserved.
Justin Reock
Chief Architect
Rogue Wave Software
Justin has over 20 years’ experience
working in various software roles and
is an outspoken free software
evangelist, delivering enterprise
solutions and community education
on databases, integration work,
architecture, and technical
leadership.
He is currently the Chief Architect at
Rogue Wave Software.
4© 2018 Rogue Wave Software, Inc. All Rights Reserved.
5© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• React is a JavaScript library that focuses on
declarative syntax and virtualization of the DOM
• It allows developers to write highly efficient
JavaScript for the purpose of rendering a UI in a
web browser
• Whereas traditional JavaScript will re-render the
entire DOM during a state change, React will only
render the parts of the DOM that have changed
6© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Created by Jordan Walke at Facebook
• First deployed on Facebook’s newsfeed in 2011,
Instagram in 2012
• Released under the MIT License as an open source
project in May of 2013
• Additional projects such as React Native for mobile and
React Fiber would follow in 2015 and 2017 respectively
7© 2018 Rogue Wave Software, Inc. All Rights Reserved.
8© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• It’s really these two keywords that sets React apart from
traditional JavaScript UI development
• React doesn’t iteratively draw UI components on the screen
• The developer defines what the final UI should look like, and
React ensures that the DOM is rendered accordingly
• This is a very significant difference from typical HTML
rendering in JavaScript, which typically centers around injecting
HTML using the innerHTML directive
Declarative and Virtualized
9© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• React also virtualizes the entire DOM and uses
JavaScript to render actual HTML in the form of React
Components
• Although you may never directly use it for reasons that
will soon become clear, React generates HTML elements
using the React.createElement() method
• Every UI element rendered in the browser will be
created by a JavaScript call to this method
Declarative and Virtualized
10© 2018 Rogue Wave Software, Inc. All Rights Reserved.
11© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Right now you may be thinking: ”Why would you ever do that
when its simple enough to just write HTML with in-line
JavaScript?
• Before you storm out of the session room, never to touch React
again, let’s look at why this is actually quite powerful
• React virtualizes the entire DOM – that really means that it
keeps a dynamic model of the UI in-memory, and can
manipulate it on the fly
• Let’s look at a demo…
12© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• We’ll render a bit of HTML using the traditional
innerHTML call, as well as through React
• Then we’ll create a second timer on the page that will
tick up using the JavaScript setInterval() function
• We’ll then demonstrate exactly why this approach is
so interesting
Just the updates, please!
13© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• This is a much different paradigm, but with JavaScript free
to own the entire DOM, we can do interesting things
• Since React just declares the UI composition and updates
itself accordingly, you don’t have to worry about redrawing
parts or all of the UI when something changes
• You can trust React to, well, react to those changes and re-
render itself only when necessary
Subtle but powerful…
14© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Another important aspect to understand is that React is
not a framework
• It’s a JavaScript library focused just on UI composition
• You’ll use it in concert with other JavaScript libraries,
such as Node.js
• This allows you the freedom to build the other parts of
your app any way you’d like, without having to commit to
an entire framework
Not a Framework
15© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• As you saw in the demo, the React library contains
a method for drawing HTML elements inside of the
DOM
• But, you may never actually need to invoke it
• JSX gives you the ability to just write your elements
in a pseudo-HTML syntax
React.createElement()
16© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• React will assemble these multiple React.createElement()
calls into a tree of components
• Then, upon every state change, React performs a “tree
reconciliation” where it examines the state of every
component and sees if anything has changed
• If something has changed, react updates that part of
the virtual DOM and re-renders the element
ReactDOM.render()
17© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• The special function render() will expect to receive as
input the design elements of your UI
• An anchor element in HTML where it should draw the
object is its second parameter
• Only one element (or a parent element with children)
can be passed, because Babel will convert these
elements into functions
ReactDOM.render()
18© 2018 Rogue Wave Software, Inc. All Rights Reserved.
ReactDOM.render(
<Button1 /><Button2 />,
document.getElementById(‘root’),
);
ReactDOM.render()
19© 2018 Rogue Wave Software, Inc. All Rights Reserved.
ReactDOM.render()
ReactDOM.render(
<div>
<Button1 /><Button2 />
</div>,
document.getElementById(‘root’),
);
20© 2018 Rogue Wave Software, Inc. All Rights Reserved.
21© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• If you promise not to get too upset, I’ll show you how
you’ll generally create elements in React
Ok now I’m really leaving…
function Title() {
return ( <div>
<h1>WTF How Is This Possible?</h1>
</div> );
}
ReactDOM.render(<Title />, document.getElementById(’root’);
22© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• So, yeah, you will write in-line ersatz HTML (really, JSX) and
pass it around as if it was native JavaScript
• It takes a little getting used to, but, it ends up being a lot
cleaner than dozens of createElement() calls
• In fact, when React compiles, it uses a library called Babel to
generate createElement() statements from the JSX
• So the JSX is really never rendered directly, it is interpreted by
Babel and converted to createElement() calls at compile time
23© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Open up the Babel test portal at https://babeljs.io
• Add some JSX to the test pane after selecting “react”
under the Presets tab
• Watch as Babel displays the equivalent React code
• Hopefully end up a little less nauseated at what JSX is
doing!
24© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Components are atomic UI elements which will combine
layout with a state and set of properties that React will
maintain
• You will create these components as either JavaScript classes
or functions, and React will use them to render UI elements
• These components are autonomous, and maintain their own
private state and properties
• They can be arranged into parent/child hierarchies, and can
flow data between them
25© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• A function component starts with a function,
obviously
• We’ve actually already seen one:
function Title() {
return ( <div>
<h1>WTF How Is This Possible?</h1>
</div> );
}
ReactDOM.render(<Title />, document.getElementById(’root’);
26© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• These can also be defined using the newer JavaScript
function arrow syntax:
const Title = (props) => {
return ( <div>
<h1>WTF How Is This Possible?</h1>
</div> );
}
ReactDOM.render(<Title />, document.getElementById(’root’);
27© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• For more complex components, you may want to take
advantage of JavaScript classes
• Those who are more comfortable with OOP as opposed
to Functional programming may prefer creating classes
• I do encourage you to get comfortable with Functional
programming, though
• It is a discipline getting more and more important as
we move to distributed and concurrent application
architectures
28© 2018 Rogue Wave Software, Inc. All Rights Reserved.
class App extends React.Component {
render() {
const profile = this.props;
return <div>
<h1>profile.title</h1>
</div>;
}
…
<App title=“Class Component” prop1=“somethingelse” />
29© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Components will automatically contain a properties
object that can be interacted with and changed
• These properties are passed in by default as function
parameters in a function component
• Or, they will be their own object, referenced with
‘this.props’ inside of a class component
• Properties are immutable, but can be set with initial
values when a component is rendered
30© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• State inside of a React component consists of two parts
• The first is the state, which is really just a primitive or
set of primitives that can be manipulated
• The second is a setter function which allows you to
update the state of a component
• Both of these entities are exposed by deconstructing a
special hook called useState() which is provided by
React
31© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• We just covered a lot of ground, but when we look at
the code this is actually very straightforward
• Let’s create a function component, and give that
component a set of properties and a state
• And let’s alter that state and watch the result in the
browser
Lets tie it all together
32© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• This is a large topic, but we’ll gently introduce it here
• Recall in the demo that we broke our UI into two
components, a Display and a Button
• The Display object had to react to state changes caused
by the Button’s onClick event handler
• We did this by passing properties into the Display
function
One-way Data Flow
33© 2018 Rogue Wave Software, Inc. All Rights Reserved.
One-Way Data Flow
function Display(props) {
return (
<div>{props.message}</div>
);
}
<Display message={counter.counterValue} />
Here, The App parent (below)
Flows property data to the
Child Display component (above)
34© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• The parent App element has the Display element as its child, so it
is able to flow data down to it
• While this isn’t the only technique for flowing data in React, this is a
pattern you will see often
• You can even pass entire functions to child components, which
the children can then execute to relay data back to the parent
• Don’t worry if this is a little confusing at this point, it is one of
React’s more advanced concepts and just takes some practice
One-Way Data Flow
35© 2018 Rogue Wave Software, Inc. All Rights Reserved.
36© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Like many things in life, there’s an easy way and a hard way to get
going with React
• The easy way is great, but it obfuscates the setup and so you
can’t really learn from it
• Let’s step through the hard way first (just listing the steps) and then
I’ll introduce the easy way
• I recommend that everyone go through the hard way at least
once so you can become familiar
• It’s a pain, but, it’s worth it to increase your knowledge of React
Let’s start playing!
37© 2018 Rogue Wave Software, Inc. All Rights Reserved.
1) Install Node.js
2) Create root directory
3) npm init
4) Install express with
npm
5) Install react and react-
dom with npm
Just to give you an idea…
6) Install webpack with npm
7) Install BabelJS with npm
8) Install nodemon
9) Install eslint
10)Create webpack app
structure….
38© 2018 Rogue Wave Software, Inc. All Rights Reserved.
Ok ok I’ll stop….
39© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Thankfully, a special Node.js module called “create-react-
app” exists for you and is kept up to date
• This module is maintained by Facebook and is an
officially supported way to create a React app
• Note that this is only suitable for single-page React
apps, but, that covers most apps since your dynamic
content will all be rendered in the DOM
Huzzah!
40© 2018 Rogue Wave Software, Inc. All Rights Reserved.
1) npx create-react-app my-cool-app
2) cd my-cool-app
3) npm start
41© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• Let’s create a Dev environment using the create-
react-app module through npx
• We’ll then make a couple modifications and watch as
nodemon automatically restarts our process
Small mercies…
42© 2018 Rogue Wave Software, Inc. All Rights Reserved.
• We’ve just scraped the surface, but hopefully you have enough to get
started
• We learned that React is a Declarative library that Virtualizes the DOM
• And we looked at React’s building blocks, components, and demonstrated
their states and properties
• Finally, we walked through setting up a Dev environment
• From here, go check out React’s official tutorial, hosted by the React
community: https://reactjs.org/tutorial/tutorial.html
• Happy hacking, and finally…
Still so much to learn!
43© 2018 Rogue Wave Software, Inc. All Rights Reserved.
LinkedIn – Only Justin Reock in the world apparently!
Twitter – @jreock - But I do get a little political on
there….
Blog - http://blog.klocwork.com/author/justin-reock/
Email – justin.reock@roguewave.com
Feel Free to Reach Out – I Get Lonely…
44© 2018 Rogue Wave Software, Inc. All Rights Reserved.
45© 2018 Rogue Wave Software, Inc. All Rights Reserved.

More Related Content

What's hot (20)

PDF
ReactJS presentation
Thanh Tuong
 
PPTX
Reactjs
Neha Sharma
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPTX
React workshop
Imran Sayed
 
PPTX
Introduction to React
Rob Quick
 
PPTX
Introduction to React JS for beginners | Namespace IT
namespaceit
 
PPTX
React js programming concept
Tariqul islam
 
PPTX
ReactJS presentation.pptx
DivyanshGupta922023
 
PPTX
React js
Oswald Campesato
 
PPTX
React js for beginners
Alessandro Valenti
 
PDF
An introduction to React.js
Emanuele DelBono
 
PDF
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
PPTX
React js - The Core Concepts
Divyang Bhambhani
 
PPTX
React-JS.pptx
AnmolPandita7
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
reactJS
Syam Santhosh
 
PPTX
[Final] ReactJS presentation
洪 鹏发
 
PPTX
What is component in reactjs
manojbkalla
 
PPTX
Its time to React.js
Ritesh Mehrotra
 
ReactJS presentation
Thanh Tuong
 
Reactjs
Neha Sharma
 
Introduction to React JS for beginners
Varun Raj
 
React workshop
Imran Sayed
 
Introduction to React
Rob Quick
 
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React js programming concept
Tariqul islam
 
ReactJS presentation.pptx
DivyanshGupta922023
 
React js for beginners
Alessandro Valenti
 
An introduction to React.js
Emanuele DelBono
 
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 
React js - The Core Concepts
Divyang Bhambhani
 
React-JS.pptx
AnmolPandita7
 
React + Redux Introduction
Nikolaus Graf
 
reactJS
Syam Santhosh
 
[Final] ReactJS presentation
洪 鹏发
 
What is component in reactjs
manojbkalla
 
Its time to React.js
Ritesh Mehrotra
 

Similar to Intro to React (20)

PDF
FRONTEND DEVELOPMENT WITH REACT.JS
IRJET Journal
 
PDF
Intro to react_v2
Feather Knee
 
PDF
Learn react by Etietop Demas
Etietop Demas
 
PPTX
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
PDF
Welcome to React & Flux !
Ritesh Kumar
 
PPTX
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
PDF
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
PDF
Introduction to React JS
Bethmi Gunasekara
 
PDF
React & Flux Workshop
Christian Lilley
 
PDF
Tech Talk on ReactJS
Atlogys Technical Consulting
 
PDF
Review on React JS
ijtsrd
 
PDF
React in Action ( PDFDrive ).pdf
almako2
 
PDF
React Tech Salon
Chenguang ZHANG
 
PPTX
React_Complete.pptx
kamalakantas
 
PPTX
React js
Nikhil Karkra
 
PPTX
React - Start learning today
Nitin Tyagi
 
PPTX
ReactJS Code Impact
Raymond McDermott
 
PDF
learning react
Eueung Mulyana
 
PDF
React - The JavaScript Library for User Interfaces
Jumping Bean
 
PDF
React Interview Question PDF By ScholarHat
Scholarhat
 
FRONTEND DEVELOPMENT WITH REACT.JS
IRJET Journal
 
Intro to react_v2
Feather Knee
 
Learn react by Etietop Demas
Etietop Demas
 
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Welcome to React & Flux !
Ritesh Kumar
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Getting Started with React, When You’re an Angular Developer
Fabrit Global
 
Introduction to React JS
Bethmi Gunasekara
 
React & Flux Workshop
Christian Lilley
 
Tech Talk on ReactJS
Atlogys Technical Consulting
 
Review on React JS
ijtsrd
 
React in Action ( PDFDrive ).pdf
almako2
 
React Tech Salon
Chenguang ZHANG
 
React_Complete.pptx
kamalakantas
 
React js
Nikhil Karkra
 
React - Start learning today
Nitin Tyagi
 
ReactJS Code Impact
Raymond McDermott
 
learning react
Eueung Mulyana
 
React - The JavaScript Library for User Interfaces
Jumping Bean
 
React Interview Question PDF By ScholarHat
Scholarhat
 
Ad

More from Justin Reock (16)

PPTX
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
PPTX
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
PPTX
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
PDF
DORA Community - Building 10x Development Organizations.pdf
Justin Reock
 
PDF
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
 
PDF
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
 
PDF
Building 10x Development Organizations.pdf
Justin Reock
 
PPTX
Open Source AI and ML, Whats Possible Today?
Justin Reock
 
PPTX
Community vs. Commercial Open Source
Justin Reock
 
PDF
Getting Started with Node.js
Justin Reock
 
PDF
Monitoring Java Applications with Prometheus and Grafana
Justin Reock
 
PPTX
Integrating Postgres with ActiveMQ and Camel
Justin Reock
 
PPTX
Node.js Deeper Dive
Justin Reock
 
PPTX
Linux 101
Justin Reock
 
PPTX
ZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
Justin Reock
 
PPTX
ZendCon - Linux 101
Justin Reock
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
DORA Community - Building 10x Development Organizations.pdf
Justin Reock
 
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
 
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
 
Building 10x Development Organizations.pdf
Justin Reock
 
Open Source AI and ML, Whats Possible Today?
Justin Reock
 
Community vs. Commercial Open Source
Justin Reock
 
Getting Started with Node.js
Justin Reock
 
Monitoring Java Applications with Prometheus and Grafana
Justin Reock
 
Integrating Postgres with ActiveMQ and Camel
Justin Reock
 
Node.js Deeper Dive
Justin Reock
 
Linux 101
Justin Reock
 
ZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
Justin Reock
 
ZendCon - Linux 101
Justin Reock
 
Ad

Recently uploaded (20)

PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PPTX
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PPTX
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
computer forensics encase emager app exp6 1.pptx
ssuser343e92
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
interacting-with-ai-2023---module-2---session-3---handout.pdf
cniclsh1
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 

Intro to React

  • 1. 1© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 2. 2© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 3. 3© 2018 Rogue Wave Software, Inc. All Rights Reserved. Justin Reock Chief Architect Rogue Wave Software Justin has over 20 years’ experience working in various software roles and is an outspoken free software evangelist, delivering enterprise solutions and community education on databases, integration work, architecture, and technical leadership. He is currently the Chief Architect at Rogue Wave Software.
  • 4. 4© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 5. 5© 2018 Rogue Wave Software, Inc. All Rights Reserved. • React is a JavaScript library that focuses on declarative syntax and virtualization of the DOM • It allows developers to write highly efficient JavaScript for the purpose of rendering a UI in a web browser • Whereas traditional JavaScript will re-render the entire DOM during a state change, React will only render the parts of the DOM that have changed
  • 6. 6© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Created by Jordan Walke at Facebook • First deployed on Facebook’s newsfeed in 2011, Instagram in 2012 • Released under the MIT License as an open source project in May of 2013 • Additional projects such as React Native for mobile and React Fiber would follow in 2015 and 2017 respectively
  • 7. 7© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 8. 8© 2018 Rogue Wave Software, Inc. All Rights Reserved. • It’s really these two keywords that sets React apart from traditional JavaScript UI development • React doesn’t iteratively draw UI components on the screen • The developer defines what the final UI should look like, and React ensures that the DOM is rendered accordingly • This is a very significant difference from typical HTML rendering in JavaScript, which typically centers around injecting HTML using the innerHTML directive Declarative and Virtualized
  • 9. 9© 2018 Rogue Wave Software, Inc. All Rights Reserved. • React also virtualizes the entire DOM and uses JavaScript to render actual HTML in the form of React Components • Although you may never directly use it for reasons that will soon become clear, React generates HTML elements using the React.createElement() method • Every UI element rendered in the browser will be created by a JavaScript call to this method Declarative and Virtualized
  • 10. 10© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 11. 11© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Right now you may be thinking: ”Why would you ever do that when its simple enough to just write HTML with in-line JavaScript? • Before you storm out of the session room, never to touch React again, let’s look at why this is actually quite powerful • React virtualizes the entire DOM – that really means that it keeps a dynamic model of the UI in-memory, and can manipulate it on the fly • Let’s look at a demo…
  • 12. 12© 2018 Rogue Wave Software, Inc. All Rights Reserved. • We’ll render a bit of HTML using the traditional innerHTML call, as well as through React • Then we’ll create a second timer on the page that will tick up using the JavaScript setInterval() function • We’ll then demonstrate exactly why this approach is so interesting Just the updates, please!
  • 13. 13© 2018 Rogue Wave Software, Inc. All Rights Reserved. • This is a much different paradigm, but with JavaScript free to own the entire DOM, we can do interesting things • Since React just declares the UI composition and updates itself accordingly, you don’t have to worry about redrawing parts or all of the UI when something changes • You can trust React to, well, react to those changes and re- render itself only when necessary Subtle but powerful…
  • 14. 14© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Another important aspect to understand is that React is not a framework • It’s a JavaScript library focused just on UI composition • You’ll use it in concert with other JavaScript libraries, such as Node.js • This allows you the freedom to build the other parts of your app any way you’d like, without having to commit to an entire framework Not a Framework
  • 15. 15© 2018 Rogue Wave Software, Inc. All Rights Reserved. • As you saw in the demo, the React library contains a method for drawing HTML elements inside of the DOM • But, you may never actually need to invoke it • JSX gives you the ability to just write your elements in a pseudo-HTML syntax React.createElement()
  • 16. 16© 2018 Rogue Wave Software, Inc. All Rights Reserved. • React will assemble these multiple React.createElement() calls into a tree of components • Then, upon every state change, React performs a “tree reconciliation” where it examines the state of every component and sees if anything has changed • If something has changed, react updates that part of the virtual DOM and re-renders the element ReactDOM.render()
  • 17. 17© 2018 Rogue Wave Software, Inc. All Rights Reserved. • The special function render() will expect to receive as input the design elements of your UI • An anchor element in HTML where it should draw the object is its second parameter • Only one element (or a parent element with children) can be passed, because Babel will convert these elements into functions ReactDOM.render()
  • 18. 18© 2018 Rogue Wave Software, Inc. All Rights Reserved. ReactDOM.render( <Button1 /><Button2 />, document.getElementById(‘root’), ); ReactDOM.render()
  • 19. 19© 2018 Rogue Wave Software, Inc. All Rights Reserved. ReactDOM.render() ReactDOM.render( <div> <Button1 /><Button2 /> </div>, document.getElementById(‘root’), );
  • 20. 20© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 21. 21© 2018 Rogue Wave Software, Inc. All Rights Reserved. • If you promise not to get too upset, I’ll show you how you’ll generally create elements in React Ok now I’m really leaving… function Title() { return ( <div> <h1>WTF How Is This Possible?</h1> </div> ); } ReactDOM.render(<Title />, document.getElementById(’root’);
  • 22. 22© 2018 Rogue Wave Software, Inc. All Rights Reserved. • So, yeah, you will write in-line ersatz HTML (really, JSX) and pass it around as if it was native JavaScript • It takes a little getting used to, but, it ends up being a lot cleaner than dozens of createElement() calls • In fact, when React compiles, it uses a library called Babel to generate createElement() statements from the JSX • So the JSX is really never rendered directly, it is interpreted by Babel and converted to createElement() calls at compile time
  • 23. 23© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Open up the Babel test portal at https://babeljs.io • Add some JSX to the test pane after selecting “react” under the Presets tab • Watch as Babel displays the equivalent React code • Hopefully end up a little less nauseated at what JSX is doing!
  • 24. 24© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Components are atomic UI elements which will combine layout with a state and set of properties that React will maintain • You will create these components as either JavaScript classes or functions, and React will use them to render UI elements • These components are autonomous, and maintain their own private state and properties • They can be arranged into parent/child hierarchies, and can flow data between them
  • 25. 25© 2018 Rogue Wave Software, Inc. All Rights Reserved. • A function component starts with a function, obviously • We’ve actually already seen one: function Title() { return ( <div> <h1>WTF How Is This Possible?</h1> </div> ); } ReactDOM.render(<Title />, document.getElementById(’root’);
  • 26. 26© 2018 Rogue Wave Software, Inc. All Rights Reserved. • These can also be defined using the newer JavaScript function arrow syntax: const Title = (props) => { return ( <div> <h1>WTF How Is This Possible?</h1> </div> ); } ReactDOM.render(<Title />, document.getElementById(’root’);
  • 27. 27© 2018 Rogue Wave Software, Inc. All Rights Reserved. • For more complex components, you may want to take advantage of JavaScript classes • Those who are more comfortable with OOP as opposed to Functional programming may prefer creating classes • I do encourage you to get comfortable with Functional programming, though • It is a discipline getting more and more important as we move to distributed and concurrent application architectures
  • 28. 28© 2018 Rogue Wave Software, Inc. All Rights Reserved. class App extends React.Component { render() { const profile = this.props; return <div> <h1>profile.title</h1> </div>; } … <App title=“Class Component” prop1=“somethingelse” />
  • 29. 29© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Components will automatically contain a properties object that can be interacted with and changed • These properties are passed in by default as function parameters in a function component • Or, they will be their own object, referenced with ‘this.props’ inside of a class component • Properties are immutable, but can be set with initial values when a component is rendered
  • 30. 30© 2018 Rogue Wave Software, Inc. All Rights Reserved. • State inside of a React component consists of two parts • The first is the state, which is really just a primitive or set of primitives that can be manipulated • The second is a setter function which allows you to update the state of a component • Both of these entities are exposed by deconstructing a special hook called useState() which is provided by React
  • 31. 31© 2018 Rogue Wave Software, Inc. All Rights Reserved. • We just covered a lot of ground, but when we look at the code this is actually very straightforward • Let’s create a function component, and give that component a set of properties and a state • And let’s alter that state and watch the result in the browser Lets tie it all together
  • 32. 32© 2018 Rogue Wave Software, Inc. All Rights Reserved. • This is a large topic, but we’ll gently introduce it here • Recall in the demo that we broke our UI into two components, a Display and a Button • The Display object had to react to state changes caused by the Button’s onClick event handler • We did this by passing properties into the Display function One-way Data Flow
  • 33. 33© 2018 Rogue Wave Software, Inc. All Rights Reserved. One-Way Data Flow function Display(props) { return ( <div>{props.message}</div> ); } <Display message={counter.counterValue} /> Here, The App parent (below) Flows property data to the Child Display component (above)
  • 34. 34© 2018 Rogue Wave Software, Inc. All Rights Reserved. • The parent App element has the Display element as its child, so it is able to flow data down to it • While this isn’t the only technique for flowing data in React, this is a pattern you will see often • You can even pass entire functions to child components, which the children can then execute to relay data back to the parent • Don’t worry if this is a little confusing at this point, it is one of React’s more advanced concepts and just takes some practice One-Way Data Flow
  • 35. 35© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 36. 36© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Like many things in life, there’s an easy way and a hard way to get going with React • The easy way is great, but it obfuscates the setup and so you can’t really learn from it • Let’s step through the hard way first (just listing the steps) and then I’ll introduce the easy way • I recommend that everyone go through the hard way at least once so you can become familiar • It’s a pain, but, it’s worth it to increase your knowledge of React Let’s start playing!
  • 37. 37© 2018 Rogue Wave Software, Inc. All Rights Reserved. 1) Install Node.js 2) Create root directory 3) npm init 4) Install express with npm 5) Install react and react- dom with npm Just to give you an idea… 6) Install webpack with npm 7) Install BabelJS with npm 8) Install nodemon 9) Install eslint 10)Create webpack app structure….
  • 38. 38© 2018 Rogue Wave Software, Inc. All Rights Reserved. Ok ok I’ll stop….
  • 39. 39© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Thankfully, a special Node.js module called “create-react- app” exists for you and is kept up to date • This module is maintained by Facebook and is an officially supported way to create a React app • Note that this is only suitable for single-page React apps, but, that covers most apps since your dynamic content will all be rendered in the DOM Huzzah!
  • 40. 40© 2018 Rogue Wave Software, Inc. All Rights Reserved. 1) npx create-react-app my-cool-app 2) cd my-cool-app 3) npm start
  • 41. 41© 2018 Rogue Wave Software, Inc. All Rights Reserved. • Let’s create a Dev environment using the create- react-app module through npx • We’ll then make a couple modifications and watch as nodemon automatically restarts our process Small mercies…
  • 42. 42© 2018 Rogue Wave Software, Inc. All Rights Reserved. • We’ve just scraped the surface, but hopefully you have enough to get started • We learned that React is a Declarative library that Virtualizes the DOM • And we looked at React’s building blocks, components, and demonstrated their states and properties • Finally, we walked through setting up a Dev environment • From here, go check out React’s official tutorial, hosted by the React community: https://reactjs.org/tutorial/tutorial.html • Happy hacking, and finally… Still so much to learn!
  • 43. 43© 2018 Rogue Wave Software, Inc. All Rights Reserved. LinkedIn – Only Justin Reock in the world apparently! Twitter – @jreock - But I do get a little political on there…. Blog - http://blog.klocwork.com/author/justin-reock/ Email – [email protected] Feel Free to Reach Out – I Get Lonely…
  • 44. 44© 2018 Rogue Wave Software, Inc. All Rights Reserved.
  • 45. 45© 2018 Rogue Wave Software, Inc. All Rights Reserved.

Editor's Notes

  • #4: Establish right to play here by explaining background
  • #8: COCOMO = Constructive Cost Model Software cost estimation model Uses a regression formula to calculate effort as time