SlideShare a Scribd company logo
Introduction to React
A workshop for COMP 523
Aaron Smith
Monday, Feb. 10, 2020
What is React?
• React is a JavaScript framework
• Used for front end web development
• Think of jQuery, but more structured
• Created and used by Facebook
• Famous for implementing a virtual dom
Timeline of front-end JavaScript frameworks
jQuery*
(2006)
AngularJS
(2010)
React
(2013)
Vue
(2014)
Angular
(2014)
* jQuery is more often considered a library than a framework
Common tasks in front-end development
Data definition, organization, and storage
Event handlers respond to user actions
Design and render HTML templates
Resolve URLs
Interact with server(s) through APIs and AJAX
App state
User actions
Templates
Routing
Data fetching
Fundamentals of React
1. JavaScript and HTML in the same file (JSX)
2. Embrace functional programming
3. Components everywhere
JavaScript and HTML in the same file
Traditional
approach
React
approach
HTML CSS JS JSX CSS or JSS
JSX: the React programming language
const first = "Aaron";
const last = "Smith";
const name = <span>{first} {last}</span>;
const listWithTitle = (
<>
<h1>COMP 523</h1>
<ul>
<li>Dr. David Stotts</li>
<li>{name}</li>
</ul>
</>
);
const list = (
<ul>
<li>Dr. David Stotts</li>
<li>{name}</li>
</ul>
);
“React is just JavaScript”
Functional programming
1. Functions are “first class citizens”
2. Variables are immutable
3. Functions have no side effects
Functional programming
Functions are “first class citizens”
let add = function() {
console.log('Now adding numbers');
const five = 3 + 2;
};
function performTask(task) {
task();
console.log('Task performed!');
}
performTask(add);
function foo() {
return function() {
console.log('What gets printed?');
};
}
foo
foo();
foo()();
Functional programming
Variables are immutable
let a = 4;
a = 2; // Mutates `a`
let b = [1, 2, 3];
b.push(4); // Mutates `b`
let c = [...b, 4]; // Does not mutate `b`
Functional programming
Functions have no side effects
const b = [];
function hasSideEffects() {
b = [0];
}
Components
Components are functions for user interfaces
let y = f(x);
Input x Output number
let y = <FancyDiv value={x} />;
Input x Output HTML
Math function:
Component function:
Anatomy of a React component
export default function MyComponent(props) {
return <div>Hello, world! My name is {props.name}</div>;
}
const html = <MyComponent name="aaron" />;
Inputs are passed through a
single argument called “props”
The function is executed as if
it was an HTML tag
The function
outputs HTML
The component is just
a function
Parameters are passed in
as HTML attributes
Component rendering
• When a component function executes, we say it “renders”
• Assume components may re-render at any time
Our job is to ensure that
every time the component re-renders,
the correct output is produced
“In React, everything is a component”
Todo application
Title
TodoForm
First step:
 mockup / wireframe
TodoList
Todo
Big idea:
 A digital to-do list
Creating a new React app
Creating a new React app is simple!
1. Install Node.js
2. Run: npx create-react-app app-name
3. New app created in folder: ./app-name
Anatomy of a new React app
public holds the initial html
document and other static assets
App is a boilerplate
starter component
index.js binds
React to the DOM
package.json configures
npm dependencies
Component Hierarchy
Title
TodoForm
TodoList
Todo
Title TodoForm
TodoList
Todo Todo Todo
App
Special list key property
• Situation: Display a dynamic array of elements
• Must specify a special “key” property for each element
• The key of an item uniquely identifies it
• Used by React internally for render optimization
• Can be any unique value (string or number)
What are hooks?
useState
useEffect
useReducer
useMemo
useRef
useCallback
We will cover
these today
We will not cover
these today
Built-in hooks:
Hooks: Special functions that allow
developers to hook into state and
lifecycle of React components.
State: One or more data values
associated with a React component
instance.
Lifecycle: The events associated with a
React component instance (create,
render, destroy, etc).
First React hook: useState
Purpose:
1. Remember values internally when the component re-renders
2. Tell React to re-render the component when the value changes
Syntax:
const [val, setVal] = useState(100);
The current value A setter function to
change the value
The initial
value to use
Predicting component re-rendering
A component will only re-render when…
1. A value inside props changes
– or –
2. A useState setter is called
Second React hook: useEffect
Purpose:
Act as an observer, running code in response to value changes
Syntax:
useEffect(() => {
console.log(`myValue was changed! New value: ${myValue}`);
}, [myValue]);
A list of values such that changes
should trigger this code to run
The code to run when
values change
Building a React project
• When you’re ready to launch your app, run this command:
npm run build
• This bundles your app into CSS/JS/HTML files and puts them in the
/build folder
• These files can be used to deploy our projects
3rd party components and libraries
• React-Router
• Redux
• Material-UI
• Bootstrap
• Font-Awesome

More Related Content

PPTX
React hooks
Ramy ElBasyouni
 
PDF
React JS - Introduction
Sergey Romaneko
 
PPTX
React hooks
Assaf Gannon
 
PPTX
React workshop
Imran Sayed
 
PDF
Understanding react hooks
Samundra khatri
 
PPTX
React + Redux Introduction
Nikolaus Graf
 
PPTX
Introduction to React JS for beginners | Namespace IT
namespaceit
 
PDF
React js use contexts and useContext hook
Piyush Jamwal
 
React hooks
Ramy ElBasyouni
 
React JS - Introduction
Sergey Romaneko
 
React hooks
Assaf Gannon
 
React workshop
Imran Sayed
 
Understanding react hooks
Samundra khatri
 
React + Redux Introduction
Nikolaus Graf
 
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React js use contexts and useContext hook
Piyush Jamwal
 

What's hot (20)

PPTX
React js programming concept
Tariqul islam
 
PPTX
React Hooks
Erez Cohen
 
PPTX
Intro to React
Eric Westfall
 
PDF
React new features and intro to Hooks
Soluto
 
PDF
React js
Rajesh Kolla
 
PPTX
Introduction to React JS for beginners
Varun Raj
 
PPT
React js
Jai Santhosh
 
PPTX
React js for beginners
Alessandro Valenti
 
PPTX
Understanding react hooks
Maulik Shah
 
PPTX
ReactJs
Sahana Banerjee
 
PPTX
React hooks
Sadhna Rana
 
PPTX
Introduction to React
Rob Quick
 
PDF
React Context API
NodeXperts
 
PPTX
React-JS.pptx
AnmolPandita7
 
PPTX
reactJS
Syam Santhosh
 
PPTX
React - Start learning today
Nitin Tyagi
 
PPTX
Intro to React
Justin Reock
 
PPTX
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
PPTX
React JS part 1
Diluka Wittahachchige
 
PPTX
React workshop presentation
Bojan Golubović
 
React js programming concept
Tariqul islam
 
React Hooks
Erez Cohen
 
Intro to React
Eric Westfall
 
React new features and intro to Hooks
Soluto
 
React js
Rajesh Kolla
 
Introduction to React JS for beginners
Varun Raj
 
React js
Jai Santhosh
 
React js for beginners
Alessandro Valenti
 
Understanding react hooks
Maulik Shah
 
React hooks
Sadhna Rana
 
Introduction to React
Rob Quick
 
React Context API
NodeXperts
 
React-JS.pptx
AnmolPandita7
 
reactJS
Syam Santhosh
 
React - Start learning today
Nitin Tyagi
 
Intro to React
Justin Reock
 
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
React JS part 1
Diluka Wittahachchige
 
React workshop presentation
Bojan Golubović
 
Ad

Similar to react-slides.pptx (20)

PDF
react-slides.pdf
DayNightGaMiNg
 
PDF
react-slides.pdf gives information about react library
janet736113
 
PPTX
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
PPTX
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PrathamSharma77833
 
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
PPTX
Dyanaimcs of business and economics unit 2
jpm071712
 
PDF
React Interview Question & Answers PDF By ScholarHat
Scholarhat
 
PPTX
Introduction to React JS.pptx
SHAIKIRFAN715544
 
PDF
Welcome to React & Flux !
Ritesh Kumar
 
PDF
React Interview Question PDF By ScholarHat
Scholarhat
 
PPTX
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 
PDF
100 React Interview questions 2024.pptx.pdf
codevincent624
 
PPTX
React_Complete.pptx
kamalakantas
 
PPTX
React js introduction about it's features
SaiM947604
 
PDF
React JS Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
PPTX
2.React tttttttttttttttttttttttttttttttt
MrVMNair
 
PPTX
ReactJS Code Impact
Raymond McDermott
 
react-slides.pdf
DayNightGaMiNg
 
react-slides.pdf gives information about react library
janet736113
 
react-slidlkjfl;kj;dlkjopidfjhopijgpoerjpofjiwoepifjopweifjepoies.pptx
PrathamSharma77833
 
TRAINING pptt efwoiefo weoifjoiewjfoifjow.pptx
PrathamSharma77833
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
Dyanaimcs of business and economics unit 2
jpm071712
 
React Interview Question & Answers PDF By ScholarHat
Scholarhat
 
Introduction to React JS.pptx
SHAIKIRFAN715544
 
Welcome to React & Flux !
Ritesh Kumar
 
React Interview Question PDF By ScholarHat
Scholarhat
 
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 
100 React Interview questions 2024.pptx.pdf
codevincent624
 
React_Complete.pptx
kamalakantas
 
React js introduction about it's features
SaiM947604
 
React JS Interview Questions PDF By ScholarHat
Scholarhat
 
Unit 2 Fundamentals of React -------.pptx
krishitajariwala72
 
2.React tttttttttttttttttttttttttttttttt
MrVMNair
 
ReactJS Code Impact
Raymond McDermott
 
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
The Future of Artificial Intelligence (AI)
Mukul
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 

react-slides.pptx

  • 1. Introduction to React A workshop for COMP 523 Aaron Smith Monday, Feb. 10, 2020
  • 2. What is React? • React is a JavaScript framework • Used for front end web development • Think of jQuery, but more structured • Created and used by Facebook • Famous for implementing a virtual dom
  • 3. Timeline of front-end JavaScript frameworks jQuery* (2006) AngularJS (2010) React (2013) Vue (2014) Angular (2014) * jQuery is more often considered a library than a framework
  • 4. Common tasks in front-end development Data definition, organization, and storage Event handlers respond to user actions Design and render HTML templates Resolve URLs Interact with server(s) through APIs and AJAX App state User actions Templates Routing Data fetching
  • 5. Fundamentals of React 1. JavaScript and HTML in the same file (JSX) 2. Embrace functional programming 3. Components everywhere
  • 6. JavaScript and HTML in the same file Traditional approach React approach HTML CSS JS JSX CSS or JSS
  • 7. JSX: the React programming language const first = "Aaron"; const last = "Smith"; const name = <span>{first} {last}</span>; const listWithTitle = ( <> <h1>COMP 523</h1> <ul> <li>Dr. David Stotts</li> <li>{name}</li> </ul> </> ); const list = ( <ul> <li>Dr. David Stotts</li> <li>{name}</li> </ul> );
  • 8. “React is just JavaScript”
  • 9. Functional programming 1. Functions are “first class citizens” 2. Variables are immutable 3. Functions have no side effects
  • 10. Functional programming Functions are “first class citizens” let add = function() { console.log('Now adding numbers'); const five = 3 + 2; }; function performTask(task) { task(); console.log('Task performed!'); } performTask(add); function foo() { return function() { console.log('What gets printed?'); }; } foo foo(); foo()();
  • 11. Functional programming Variables are immutable let a = 4; a = 2; // Mutates `a` let b = [1, 2, 3]; b.push(4); // Mutates `b` let c = [...b, 4]; // Does not mutate `b`
  • 12. Functional programming Functions have no side effects const b = []; function hasSideEffects() { b = [0]; }
  • 13. Components Components are functions for user interfaces let y = f(x); Input x Output number let y = <FancyDiv value={x} />; Input x Output HTML Math function: Component function:
  • 14. Anatomy of a React component export default function MyComponent(props) { return <div>Hello, world! My name is {props.name}</div>; } const html = <MyComponent name="aaron" />; Inputs are passed through a single argument called “props” The function is executed as if it was an HTML tag The function outputs HTML The component is just a function Parameters are passed in as HTML attributes
  • 15. Component rendering • When a component function executes, we say it “renders” • Assume components may re-render at any time Our job is to ensure that every time the component re-renders, the correct output is produced
  • 16. “In React, everything is a component”
  • 17. Todo application Title TodoForm First step:  mockup / wireframe TodoList Todo Big idea:  A digital to-do list
  • 18. Creating a new React app Creating a new React app is simple! 1. Install Node.js 2. Run: npx create-react-app app-name 3. New app created in folder: ./app-name
  • 19. Anatomy of a new React app public holds the initial html document and other static assets App is a boilerplate starter component index.js binds React to the DOM package.json configures npm dependencies
  • 21. Special list key property • Situation: Display a dynamic array of elements • Must specify a special “key” property for each element • The key of an item uniquely identifies it • Used by React internally for render optimization • Can be any unique value (string or number)
  • 22. What are hooks? useState useEffect useReducer useMemo useRef useCallback We will cover these today We will not cover these today Built-in hooks: Hooks: Special functions that allow developers to hook into state and lifecycle of React components. State: One or more data values associated with a React component instance. Lifecycle: The events associated with a React component instance (create, render, destroy, etc).
  • 23. First React hook: useState Purpose: 1. Remember values internally when the component re-renders 2. Tell React to re-render the component when the value changes Syntax: const [val, setVal] = useState(100); The current value A setter function to change the value The initial value to use
  • 24. Predicting component re-rendering A component will only re-render when… 1. A value inside props changes – or – 2. A useState setter is called
  • 25. Second React hook: useEffect Purpose: Act as an observer, running code in response to value changes Syntax: useEffect(() => { console.log(`myValue was changed! New value: ${myValue}`); }, [myValue]); A list of values such that changes should trigger this code to run The code to run when values change
  • 26. Building a React project • When you’re ready to launch your app, run this command: npm run build • This bundles your app into CSS/JS/HTML files and puts them in the /build folder • These files can be used to deploy our projects
  • 27. 3rd party components and libraries • React-Router • Redux • Material-UI • Bootstrap • Font-Awesome