SlideShare a Scribd company logo
REACT JS
(CLASS COMPONENTS)
LECTURE- 10
Today’s Agenda
 TwoTypes Of Components
 Class Components
 HowTo Create Class Components
 Industry Recommended Way Of Structuring A React Application
TwoTypes Of React Component
 As discussed previously, React lets us define components in two
ways:
 Using Functions and are called as Function based components
 Using Classes and are called as Class based components
 Till now we have discussed about Function based components and
now we will understand Class based components.
HowTo Create A
Class Based Component ?
 To create a class based Component we need to take 2 steps:
 Create your own class that extends the React.Component class
 Define the render() method which must return your component
 As mentioned previously , we must extend the
React.Component class in our class as shown below
class App extends React.Component {
.......
}
Step 1:
ExtendingThe Component Class
Why Extending
React.Component Is Needed ?
 In React, by extending the React.Component class, we
 can pass props to our component.
 inherit methods from React.Component class, like the lifecycle methods
(componentDidMount(), componentDidUpdate(),
componentWillUnmount() etc.
 can set state of a class based component using the setState() method
 The method render() is the only required method in a class
component.
 It is seen as a normal function but render() has to return
something whether it is null.
 When the component file is called React automatically calls the
render() method by default because that component needs to
display the HTML markup or we can say JSX .
Step 2:
DefineThe render() Method
What Can render() Return ?
 When called, the method render() should return one of the following
types:
 React elements.Typically created via JSX.
 Fragments. Let’s us return multiple elements from render.
 Portals. Let’s us render children into a different DOM subtree.
 String and numbers.These are rendered as text nodes in the DOM.
 Booleans or null. Render nothing.
class App extends Component {
render(){
return <h1>Hello, World!</h1>;
}
}
Step 2:
Override The render() Method
 Create a Class Based React component that returns the
message Hello User Jee!
Exercise
Exercise

<body>
<div id="root"></div>
<script type="text/babel">
class App extends React.Component {
render() {
let myElement = <h1>Hello User Jee!!</h1>;
return myElement;
}
}
let mydiv = document.querySelector("#root");
ReactDOM.render(<App />, mydiv);
</script>
</body>
index.html
Solution:
Changes Done W.R.T. React 18
 We might have noticed that when we use React 18 and call the
method ReactDOM.render() we get a warning message which says
that we must use createRoot() instead of ReactDOM.render() in React
18.
 This is because React 18 introduces a new root API for rendering our
components.
Two Impt Benefits Of Root API
 This new root API :
 provides better control for managing roots.
 enables concurrent rendering , that will let React prepare many versions
of the UI at the same time.
Changes Done W.R.T. React 18
 Previous code:
let myDiv = document.querySelector("#root");
ReactDOM.render(<App />, myDiv);
 New code:
let myDiv = document.querySelector("#root");
let root = ReactDOM.createRoot(myDiv);
root.render(<App />);

<body>
<div id="root"></div>
<script type="text/babel">
class App extends React.Component {
render() {
let myElement = <h1>Hello Userjee!!</h1>;
return myElement;
}
}
let myDiv = document.querySelector("#root");
let root = ReactDOM.createRoot(myDiv);
root.render(<App />);
</script>
</body>
index.html
Improved Solution
 Rewrite the previous React component using external
JavaScript
Exercise

<!DOCTYPE html>
<html lang="en">
<head>
<script
crossorigin
src="https://unpkg.com/react@18/umd/react.development.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<title>Class based react element</title>
</head>
<body>
<div id="root"></div>
<script type="text/babel" src="App.js"></script>
</body>
</html>
index.html
Solution

class App extends React.Component {
render() {
let myElement = <h1>Hello User Jee!!</h1>;
return myElement;
}
}
let mydiv = document.querySelector("#root");
let root = ReactDOM.createRoot(myDiv);
root.render(<App />);
App.js
Solution
React Layout
 Now we are going to talk about the proper conventional layout for
React.
 We had been making a single component and we rendered it directly
into the DOM.
 This is good for learning basics of React but not at all an industry
recommended approach
React Layout
 Most of the React Apps we will build are always going have more
than 1 component
React Layout
 So its good to keep these components in separate files
 Thus a general rule is :
 ONE COMPONENT PER FILE with the file name as component name
React Layout
 Finally we create our App component inside App.js file
 This is our top level component and it combines all other
components into a single component and renders it.
 At last , inside our index.html we attach all the js files using
<script> and they get rendered via App.js
React Layout
 To display a “HelloThere!!!” message on the screen. we will create the
following file:
1. Hello.js
2. App.js
3. index.html
Hello.js
 Here we have created our Hello component in a separate file and
the file name is the same as the component name.
class Hello extends React.Component{
render() {
return <h1>Hello There!!!</h1>
}
}
Hello,js
App.js
class App extends React.Component{
render (){
return(
<div>
<Hello/>
</div>
)
}
}
let mydiv = document.querySelector("#root");
let root = ReactDOM.createRoot(myDiv);
root.render(<App />);
App.js
App.js
 Now we have created our app component in the App.js file.
 It combines our other components into a single element.
 And then we rendered it into the DOM.
 So the App.js file is an entry point in our code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>App Layout Demo</title>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-
dom.development.js"></script>
<script src="https://unpkg.com/babel-
standalone@6.15.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script src="Hello.js" type="text/babel"></script>
<script src="App.js" type="text/babel"></script>
</body>
</html>
index.html
Output
class Hello extends React.Component
{
render(){
.......
}
}
Hello.js
class Bye extends React.Component
{
render(){
.......
}
}
Bye.js
App.js
<html>
…….
<script src=“Hello.js” type=“text/babel”></script>
<script src=“Bye.js” type=“text/babel”></script>
<script src=“App.js” type=“text/babel”></script>
</html>
index.html
class App extends React.Component
{
render(){
return (
<div>
<Hello />
<Bye />
</div>);
}
}
Final App Layout

More Related Content

Similar to React JS Lecture 10.pptx Our clg lecture

Similar to React JS Lecture 10.pptx Our clg lecture (20)

class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptx
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
 
Presentation1
Presentation1Presentation1
Presentation1
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
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 - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
React js
React jsReact js
React js
 
React
ReactReact
React
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdf
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
reatppt.pptx
reatppt.pptxreatppt.pptx
reatppt.pptx
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
ReactJS (1)
ReactJS (1)ReactJS (1)
ReactJS (1)
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Pluginkla2019 - React Presentation
Pluginkla2019 - React PresentationPluginkla2019 - React Presentation
Pluginkla2019 - React Presentation
 
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 outbox
React outboxReact outbox
React outbox
 

Recently uploaded

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单ewymefz
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单ocavb
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单nscud
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单ewymefz
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay
 
Investigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesInvestigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesStarCompliance.io
 
Computer Presentation.pptx ecommerce advantage s
Computer Presentation.pptx ecommerce advantage sComputer Presentation.pptx ecommerce advantage s
Computer Presentation.pptx ecommerce advantage sMAQIB18
 
Uber Ride Supply Demand Gap Analysis Report
Uber Ride Supply Demand Gap Analysis ReportUber Ride Supply Demand Gap Analysis Report
Uber Ride Supply Demand Gap Analysis ReportSatyamNeelmani2
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .NABLAS株式会社
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单nscud
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单ewymefz
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJames Polillo
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单vcaxypu
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...correoyaya
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样axoqas
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Subhajit Sahu
 
tapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive datatapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive datatheahmadsaood
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsalex933524
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...John Andrews
 

Recently uploaded (20)

一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
Investigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesInvestigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_Crimes
 
Computer Presentation.pptx ecommerce advantage s
Computer Presentation.pptx ecommerce advantage sComputer Presentation.pptx ecommerce advantage s
Computer Presentation.pptx ecommerce advantage s
 
Uber Ride Supply Demand Gap Analysis Report
Uber Ride Supply Demand Gap Analysis ReportUber Ride Supply Demand Gap Analysis Report
Uber Ride Supply Demand Gap Analysis Report
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
Innovative Methods in Media and Communication Research by Sebastian Kubitschk...
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
tapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive datatapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive data
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 

React JS Lecture 10.pptx Our clg lecture

  • 2. Today’s Agenda  TwoTypes Of Components  Class Components  HowTo Create Class Components  Industry Recommended Way Of Structuring A React Application
  • 3. TwoTypes Of React Component  As discussed previously, React lets us define components in two ways:  Using Functions and are called as Function based components  Using Classes and are called as Class based components  Till now we have discussed about Function based components and now we will understand Class based components.
  • 4. HowTo Create A Class Based Component ?  To create a class based Component we need to take 2 steps:  Create your own class that extends the React.Component class  Define the render() method which must return your component
  • 5.  As mentioned previously , we must extend the React.Component class in our class as shown below class App extends React.Component { ....... } Step 1: ExtendingThe Component Class
  • 6. Why Extending React.Component Is Needed ?  In React, by extending the React.Component class, we  can pass props to our component.  inherit methods from React.Component class, like the lifecycle methods (componentDidMount(), componentDidUpdate(), componentWillUnmount() etc.  can set state of a class based component using the setState() method
  • 7.  The method render() is the only required method in a class component.  It is seen as a normal function but render() has to return something whether it is null.  When the component file is called React automatically calls the render() method by default because that component needs to display the HTML markup or we can say JSX . Step 2: DefineThe render() Method
  • 8. What Can render() Return ?  When called, the method render() should return one of the following types:  React elements.Typically created via JSX.  Fragments. Let’s us return multiple elements from render.  Portals. Let’s us render children into a different DOM subtree.  String and numbers.These are rendered as text nodes in the DOM.  Booleans or null. Render nothing.
  • 9. class App extends Component { render(){ return <h1>Hello, World!</h1>; } } Step 2: Override The render() Method
  • 10.  Create a Class Based React component that returns the message Hello User Jee! Exercise
  • 12.  <body> <div id="root"></div> <script type="text/babel"> class App extends React.Component { render() { let myElement = <h1>Hello User Jee!!</h1>; return myElement; } } let mydiv = document.querySelector("#root"); ReactDOM.render(<App />, mydiv); </script> </body> index.html Solution:
  • 13. Changes Done W.R.T. React 18  We might have noticed that when we use React 18 and call the method ReactDOM.render() we get a warning message which says that we must use createRoot() instead of ReactDOM.render() in React 18.  This is because React 18 introduces a new root API for rendering our components.
  • 14. Two Impt Benefits Of Root API  This new root API :  provides better control for managing roots.  enables concurrent rendering , that will let React prepare many versions of the UI at the same time.
  • 15. Changes Done W.R.T. React 18  Previous code: let myDiv = document.querySelector("#root"); ReactDOM.render(<App />, myDiv);  New code: let myDiv = document.querySelector("#root"); let root = ReactDOM.createRoot(myDiv); root.render(<App />);
  • 16.  <body> <div id="root"></div> <script type="text/babel"> class App extends React.Component { render() { let myElement = <h1>Hello Userjee!!</h1>; return myElement; } } let myDiv = document.querySelector("#root"); let root = ReactDOM.createRoot(myDiv); root.render(<App />); </script> </body> index.html Improved Solution
  • 17.  Rewrite the previous React component using external JavaScript Exercise
  • 18.  <!DOCTYPE html> <html lang="en"> <head> <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js" ></script> <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" ></script> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> <title>Class based react element</title> </head> <body> <div id="root"></div> <script type="text/babel" src="App.js"></script> </body> </html> index.html Solution
  • 19.  class App extends React.Component { render() { let myElement = <h1>Hello User Jee!!</h1>; return myElement; } } let mydiv = document.querySelector("#root"); let root = ReactDOM.createRoot(myDiv); root.render(<App />); App.js Solution
  • 20. React Layout  Now we are going to talk about the proper conventional layout for React.  We had been making a single component and we rendered it directly into the DOM.  This is good for learning basics of React but not at all an industry recommended approach
  • 21. React Layout  Most of the React Apps we will build are always going have more than 1 component
  • 22. React Layout  So its good to keep these components in separate files  Thus a general rule is :  ONE COMPONENT PER FILE with the file name as component name
  • 23. React Layout  Finally we create our App component inside App.js file  This is our top level component and it combines all other components into a single component and renders it.  At last , inside our index.html we attach all the js files using <script> and they get rendered via App.js
  • 24. React Layout  To display a “HelloThere!!!” message on the screen. we will create the following file: 1. Hello.js 2. App.js 3. index.html
  • 25. Hello.js  Here we have created our Hello component in a separate file and the file name is the same as the component name. class Hello extends React.Component{ render() { return <h1>Hello There!!!</h1> } } Hello,js
  • 26. App.js class App extends React.Component{ render (){ return( <div> <Hello/> </div> ) } } let mydiv = document.querySelector("#root"); let root = ReactDOM.createRoot(myDiv); root.render(<App />); App.js
  • 27. App.js  Now we have created our app component in the App.js file.  It combines our other components into a single element.  And then we rendered it into the DOM.  So the App.js file is an entry point in our code.
  • 28. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>App Layout Demo</title> <script src="https://unpkg.com/react@18/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@18/umd/react- dom.development.js"></script> <script src="https://unpkg.com/babel- standalone@6.15.0/babel.min.js"></script> </head> <body> <div id="root"></div> <script src="Hello.js" type="text/babel"></script> <script src="App.js" type="text/babel"></script> </body> </html> index.html
  • 30. class Hello extends React.Component { render(){ ....... } } Hello.js class Bye extends React.Component { render(){ ....... } } Bye.js App.js <html> ……. <script src=“Hello.js” type=“text/babel”></script> <script src=“Bye.js” type=“text/babel”></script> <script src=“App.js” type=“text/babel”></script> </html> index.html class App extends React.Component { render(){ return ( <div> <Hello /> <Bye /> </div>); } } Final App Layout