(Go: >> BACK << -|- >> HOME <<)

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
App state
Event handlers respond to user actions
User actions
Design and render HTML templates
Templates
Resolve URLs
Routing
Interact with server(s) through APIs and AJAX
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
TodoList
Todo
Big idea:
 A digital to-do list
First step:
 mockup / wireframe
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
App is a boilerplate
starter component
public holds the initial html
document and other static assets
package.json configures
npm dependencies
index.js binds
React to the DOM
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
2. A useState setter is called
– or –
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 served from an AWS S3 bucket
3rd party components and libraries
• React-Router
• Redux
• Material-UI
• Bootstrap
• Font-Awesome
• SWR

More Related Content

Similar to react-slides.pdf gives information about react library

How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
BOSC Tech Labs
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
BOSC Tech Labs
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
Remo Jansen
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
SamyakShetty2
 
Intro react js
Intro react jsIntro react js
Intro react js
Vijayakanth MP
 
ReactJS
ReactJSReactJS
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
ArthyR3
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
Pratik Majumdar
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
Jeff Durta
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
Jennifer Estrada
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
reatppt.pptx
reatppt.pptxreatppt.pptx
What are the components in React?
What are the components in React?What are the components in React?
What are the components in React?
BOSC Tech Labs
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
Codifly
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
Karmanjay Verma
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
Matteo Manchi
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
Lama K Banna
 
Enhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order component
Yao Nien Chung
 

Similar to react-slides.pdf gives information about react library (20)

How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
 
React Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptxReact Hooks Best Practices in 2022.pptx
React Hooks Best Practices in 2022.pptx
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
REACT pdf.docx
REACT pdf.docxREACT pdf.docx
REACT pdf.docx
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
 
Intro react js
Intro react jsIntro react js
Intro react js
 
ReactJS
ReactJSReactJS
ReactJS
 
REACTJS.pdf
REACTJS.pdfREACTJS.pdf
REACTJS.pdf
 
GDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJSGDSC NITS Presents Kickstart into ReactJS
GDSC NITS Presents Kickstart into ReactJS
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
reatppt.pptx
reatppt.pptxreatppt.pptx
reatppt.pptx
 
What are the components in React?
What are the components in React?What are the components in React?
What are the components in React?
 
2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack2018 05-16 Evolving Technologies: React, Babel & Webpack
2018 05-16 Evolving Technologies: React, Babel & Webpack
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
React Native for multi-platform mobile applications
React Native for multi-platform mobile applicationsReact Native for multi-platform mobile applications
React Native for multi-platform mobile applications
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
 
Enhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order componentEnhance react app with patterns - part 1: higher order component
Enhance react app with patterns - part 1: higher order component
 

Recently uploaded

一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
uuuot
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
crioux1
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
Larry Smarr
 
Interaction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance MetricInteraction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance Metric
ScyllaDB
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
ishalveerrandhawa1
 
Data Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber SecurityData Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber Security
anupriti
 
How Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global ScaleHow Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global Scale
ScyllaDB
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
James Anderson
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
ScyllaDB
 
Hire a private investigator to get cell phone records
Hire a private investigator to get cell phone recordsHire a private investigator to get cell phone records
Hire a private investigator to get cell phone records
HackersList
 
Blockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre timesBlockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre times
anupriti
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum ThreatsNavigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
anupriti
 
STKI Israeli Market Study 2024 final v1
STKI Israeli Market Study 2024 final  v1STKI Israeli Market Study 2024 final  v1
STKI Israeli Market Study 2024 final v1
Dr. Jimmy Schwarzkopf
 
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
amitchopra0215
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
SATYENDRA100
 

Recently uploaded (20)

一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
 
Lessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien RiouxLessons Of Binary Analysis - Christien Rioux
Lessons Of Binary Analysis - Christien Rioux
 
The Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU CampusesThe Increasing Use of the National Research Platform by the CSU Campuses
The Increasing Use of the National Research Platform by the CSU Campuses
 
Interaction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance MetricInteraction Latency: Square's User-Centric Mobile Performance Metric
Interaction Latency: Square's User-Centric Mobile Performance Metric
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 
Calgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptxCalgary MuleSoft Meetup APM and IDP .pptx
Calgary MuleSoft Meetup APM and IDP .pptx
 
Data Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber SecurityData Protection in a Connected World: Sovereignty and Cyber Security
Data Protection in a Connected World: Sovereignty and Cyber Security
 
How Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global ScaleHow Netflix Builds High Performance Applications at Global Scale
How Netflix Builds High Performance Applications at Global Scale
 
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating AppsecGDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
GDG Cloud Southlake #34: Neatsun Ziv: Automating Appsec
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
Running a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU ImpactsRunning a Go App in Kubernetes: CPU Impacts
Running a Go App in Kubernetes: CPU Impacts
 
Hire a private investigator to get cell phone records
Hire a private investigator to get cell phone recordsHire a private investigator to get cell phone records
Hire a private investigator to get cell phone records
 
Blockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre timesBlockchain and Cyber Defense Strategies in new genre times
Blockchain and Cyber Defense Strategies in new genre times
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum ThreatsNavigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
Navigating Post-Quantum Blockchain: Resilient Cryptography in Quantum Threats
 
STKI Israeli Market Study 2024 final v1
STKI Israeli Market Study 2024 final  v1STKI Israeli Market Study 2024 final  v1
STKI Israeli Market Study 2024 final v1
 
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
 

react-slides.pdf gives information about react library

  • 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 App state Event handlers respond to user actions User actions Design and render HTML templates Templates Resolve URLs Routing Interact with server(s) through APIs and AJAX 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 TodoList Todo Big idea:  A digital to-do list First step:  mockup / wireframe
  • 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 App is a boilerplate starter component public holds the initial html document and other static assets package.json configures npm dependencies index.js binds React to the DOM
  • 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 2. A useState setter is called – or –
  • 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 served from an AWS S3 bucket
  • 27. 3rd party components and libraries • React-Router • Redux • Material-UI • Bootstrap • Font-Awesome • SWR