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

PPTX
Intro to React
PPTX
React JS: A Secret Preview
PDF
React js
PDF
React JS - Introduction
ODP
Introduction to ReactJS
PPTX
React js programming concept
PPTX
Introduction to react_js
PPTX
Reactjs
Intro to React
React JS: A Secret Preview
React js
React JS - Introduction
Introduction to ReactJS
React js programming concept
Introduction to react_js
Reactjs

What's hot (20)

PPTX
Introduction to React JS
PPTX
React workshop
PPTX
React JS - A quick introduction tutorial
PPTX
reactJS
PPTX
[Final] ReactJS presentation
PDF
ReactJS presentation
PPTX
ReactJS presentation.pptx
PPTX
Introduction to React JS for beginners
PPTX
React workshop presentation
PPTX
What is component in reactjs
PDF
WEB DEVELOPMENT USING REACT JS
PDF
Introduction to React JS
PPTX
Introduction to React JS for beginners | Namespace IT
PPTX
PPTX
React-JS.pptx
PDF
An introduction to React.js
PPT
React js
PPTX
React js
PPTX
Presentation on "An Introduction to ReactJS"
Introduction to React JS
React workshop
React JS - A quick introduction tutorial
reactJS
[Final] ReactJS presentation
ReactJS presentation
ReactJS presentation.pptx
Introduction to React JS for beginners
React workshop presentation
What is component in reactjs
WEB DEVELOPMENT USING REACT JS
Introduction to React JS
Introduction to React JS for beginners | Namespace IT
React-JS.pptx
An introduction to React.js
React js
React js
Presentation on "An Introduction to ReactJS"
Ad

Similar to Intro to React (20)

PDF
FRONTEND DEVELOPMENT WITH REACT.JS
PDF
Intro to react_v2
PDF
Learn react by Etietop Demas
PPTX
Reactjs notes.pptx for web development- tutorial and theory
PDF
Welcome to React & Flux !
PPTX
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
PDF
Getting Started with React, When You’re an Angular Developer
PDF
React & Flux Workshop
PDF
Tech Talk on ReactJS
PDF
Review on React JS
PDF
React in Action ( PDFDrive ).pdf
PDF
React Tech Salon
PPTX
React_Complete.pptx
PPTX
React - Start learning today
PPTX
React js for beginners
PPTX
ReactJS Code Impact
PDF
learning react
PDF
React - The JavaScript Library for User Interfaces
PDF
React Interview Question PDF By ScholarHat
PPTX
How to react: Chapter 1, The Beginning
FRONTEND DEVELOPMENT WITH REACT.JS
Intro to react_v2
Learn react by Etietop Demas
Reactjs notes.pptx for web development- tutorial and theory
Welcome to React & Flux !
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
Getting Started with React, When You’re an Angular Developer
React & Flux Workshop
Tech Talk on ReactJS
Review on React JS
React in Action ( PDFDrive ).pdf
React Tech Salon
React_Complete.pptx
React - Start learning today
React js for beginners
ReactJS Code Impact
learning react
React - The JavaScript Library for User Interfaces
React Interview Question PDF By ScholarHat
How to react: Chapter 1, The Beginning
Ad

More from Justin Reock (19)

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

Recently uploaded (20)

PDF
infoteam HELLAS company profile 2025 presentation
PDF
What Makes a Great Data Visualization Consulting Service.pdf
PDF
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
PPTX
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
Lesson-3-Operation-System-Support.pptx-I
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PDF
Odoo Construction Management System by CandidRoot
PPTX
Human-Computer Interaction for Lecture 1
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PPTX
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
PPTX
SAP Business AI_L1 Overview_EXTERNAL.pptx
PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PDF
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PPTX
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
PDF
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
PPTX
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
PPTX
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
infoteam HELLAS company profile 2025 presentation
What Makes a Great Data Visualization Consulting Service.pdf
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
Lesson-3-Operation-System-Support.pptx-I
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Odoo Construction Management System by CandidRoot
Human-Computer Interaction for Lecture 1
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
Bandicam Screen Recorder 8.2.1 Build 2529 Crack
SAP Business AI_L1 Overview_EXTERNAL.pptx
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
Top 10 Project Management Software for Small Teams in 2025.pdf
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx

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