React 18
React 18
BY
-SUDHAKAR
SHARMA
REACT INTRODUCTION
● Overview of frameworks, libraries for client
● Using VS Code
Components
● Between component child communication
● Refs
STYLING COMPONENTS
● CSS Styling
● PureComponents
● Fragments
REACT HOOKS
● Introducing Hooks
● Hooks at a Glance
● Rules of Hooks
● Building Your Own Hooks
● Hooks API Reference
● Hooks FAQ
● Validating Props
● Using References
● Demo apps
data
● HTTP POST, DELETE, UPDATE
● Handing Errors
● react-router vs react-router-dom
REACT MATERIAL UI
ERROR HANDLING
● Transitions
● Suspense Features
WEBPACK PRIMER
● What is webpack
● Why webpack
DEPLOYING ON CLOUD
● Firebase Deployment
26-10-2023
What is Solution?
- Better build SPA [Single Page Applications]
- Can we build SPA with JS and JQ? Yes
- JS & JQ need lot of DOM manipulations
- Lot of coding
- Heavy
- Slow
What is solution?
- knockout js
- backbone js
- ember js
- vue js
- react js
- angular js & angular
27-10-2023
Features of React:
1. It is component based.
- Easy to reuse
- Easy to extend
- Easy to upgrade
- Easy to build
markup => bytes => chars => token => node =>
DOM => layout => render => paint
3. It is faster
4. It is modular
What is React?
What are the Features of React?
1. Component Based
2. Virtual DOM
3. Modular
4. Faster
5. Light weight
C:\> node -v
C:\> npm -v
a) Live Server
b) VsCode Icons
c) IntelliSense for CSS class names
in HTML
D:\react-site
>npm init -y
[package.json]
index.html
home.html
React CDN :
https://legacy.reactjs.org/docs/cdn-links.html
Babel :
https://babeljs.io/docs/babel-standalone
Ex:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Index</title>
</head>
<body>
<h1>Welcome to Our Website</h1>
<p>This page is not using React.</p>
<p>React is in our <a
href="home.html">Home</a></p>
</body>
</html>
home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>Home</title>
<script crossorigin
src="https://unpkg.com/react@18/umd/react.devel
opment.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>
<script type="text/babel">
ReactDOM.render("Welcome to React 17",
document.getElementById("root"));
</script>
</head>
<body>
<noscript>Please enable JavaScript.</noscript>
<h2>Home</h2>
<div id="root"></div>
</body>
</html>
31-10-2023
Ex:
D:\> npx create-react-app
shopping-react
React Project
Infrastructure
public It comprises of
static resources
[html, images, text ,
pdf, videos etc..]
src - It comprises of
dynamic resources
[.css, .js, .ts, .scss,
.tsx, .jsx.. ]
.gitignore It comprises of
configuration of resources which are to
be ignored while
collabrating with GIT repository.
package.json It comprises of
project meta data.
[name, version,
license, dependencies..]
package-lock.json It comprises of
dependencies meta data.
Readme.md It is help
documentation for project.
http://localhost:3000
src / app.js
function App()
{
return (
<div>
<h1> Welcome to React
</h1>
</div>
)
}
1-11-2023
Summary:
>npx create-react-app shopping-react
"login.jsx"
2. Go to index.js
const root =
ReactDOM.createRoot(document.getElementById
('root'));
root.render(
<React.StrictMode>
<Login />
</React.StrictMode>
);
3. Run app
http://localhost:3000
JavaScript Topics
- Modules
- Functions
2-11-2023
JavaScript Functions
1. Function Declaration
2. Function Expression
3. Function Closure
4. Function Parameters
5. Function Callbacks
6. Function Promises
7. Function Return
8. Function Recursion
9. Arrow Functions
a) Function Declaration
b) Function Expression
Syntax: Declaration
function Name()
{
}
Syntax: Expression
}
Note: A function expression allows to change the
functionality according to state and situation. It
uses IIFE pattern. [Immediately Invoked Function
Expression]
Syntax:
(function() {
})();
hello();
function Hello(params)
{
}
Ex:
<script>
var result;
var password = prompt("Enter Password");
if(password==="admin"){
result = function(){
document.write("Success..");
}
} else {
result = function(){
document.write("invalid..");
}
}
result();
</script>
Ex:
<script>
function Demo(id, name, stock, cities, rating,
print){
print();
document.write(`
id=${id} <br>
Name=${name}<br>
Stock=${stock} <br>
Cities=${cities.join("-->")} <br>
Rating: ${rating.rate} [${rating.count}]
<br>
`);
}
Demo(1, "TV", true, ["Delhi", "Hyd"], {rate:4.2,
count:3000},
function(){document.write("Hello<br>")});
</script>
Ex:
<script>
function Demo(title,...details)
{
var [id, name, price, stock] = details;
document.write(`
<h2>${title}</h2>
Id=${id} <br>
Name=${name} <br>
Price=${price} <br>
Stock=${stock}
`);
}
Demo("Product Details",1, "TV", 54600.44,
true);
</script>
Ex:
<script>
function Demo(id, name, price)
{
document.write(`
ID = ${id} <br>
Name = ${name} <br>
Price = ${price}
`);
}
var details = [1, "Mobile", 45000.33];
Demo(...details);
</script>
Ex:
<script>
function Addition(a, b)
{
return a + b;
}
function Result(){
document.write("Addition=" +
Addition(20,30));
}
Result();
</script>
Ex:
<script>
function Hello(){
return function(){
return "Welcome to React";
}
}
document.write(Hello()());
</script>
6-11-2023
a) JavaScript Function
b) JavaScript Class
}
(or)
export function Login() {
}
2. Every function component must return mark. It
can't be void.
return(
<h1>React</h1>
=> invalid
<p> JavaScript Library </p>
)
return(
<div>
<h1>React</h1>
=> valid
<p> JavaScript Library
</p>
</div>
)
return(
<>
<h1> React </h1>
=> valid
<p> JavaScript Library </p>
</>
)
return(
<React.Fragment>
<h1> React </h1>
=> valid
<p> JavaScript Library
</p>
</React.Fragment>
)
return(
<div>
<img src="pic.jpg">
=> invalid
<input type="text">
=> invalid
</div>
)
return(
<div>
<img src="pic.jpg"> </img>
=> valid
<input type="text">
</input>
</div>
)
(or)
return(
<div>
<img src="pic.jpg" />
<input type="text" />
=> valid
</div>
)
a) login.js
b) login.css
c) login.test.js
[login.spec.js]
register.jsx
register.css
register.jsx
import "./register.css";
register.css
form {
border:1px solid gray;
box-shadow: 2px black;
padding: 20px;
border-radius: 20px;
width: 20%;
}
main {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.btn-register {
background-color: black;
color:white;
font-size: 20px;
padding: 5px;
width: 100%;
}
input {
width: 100%;
font-size: 20px;
}
const root =
ReactDOM.createRoot(document.getElementById
('root'));
root.render(
<React.StrictMode>
<Register />
</React.StrictMode>
);
7-11-2023
import
'../node_modules/bootstrap/dist/css/bootstrap.css';
import
'../node_modules/bootstrap-icons/font/bootstrap-ic
ons.css';
Ex:
register.jsx
export function Register()
{
return(
<>
<main className="d-flex
justify-content-center mt-4">
<form className="border border-2
border-dark rounded p-4">
<h2 className="bi
bi-person-fill">Register User</h2>
<dl>
<dt>User Name</dt>
<dd><input type="text"
className="form-control" /></dd>
<dt>Password</dt>
<dd><input type="password"
className="form-control"></input></dd>
<dt>Age</dt>
<dd><input type="number"
className="form-control" /></dd>
<dt>Email</dt>
<dd><input type="email"
className="form-control" /></dd>
</dl>
<button className="btn btn-primary
w-100">Register</button>
</form>
</main>
</>
)
}
Netflix Design:
1. Add a new folder into project "src" by name
"Netflix"
-netflix-index
netflix-index.jsx
netflix-index.css
-netflix-header
netflix-header.jsx
netflix-header.css
-netflix-main
netflix-main.jsx
netflix-main.css
-netflix-register
netflix-register.jsx
netflix-register.css
Note: You can access and use any component in
another component by following 2 steps
Step-1: Import the component library
<NetflixHeader> </NetflixHeader>
(or)
<NetflixHeader />
NETFLIX REGISTER:-
NETFLIX.REGISTER.JSX:-
NETFLIX-HEADER:-
.brand-title {
font-size: 30px;
color:red;
font-weight: bold;
font-family: Arial;
}
NETFLIX-HEADER.JSX:
import './netflix-header.css';
NETFLIX-INDEX:-
NETFLIX-INDEX.CSS
.bg-image {
height: 100vh;
background-image:
url("../../../public/netflixbanner.jpg");
background-size: cover;
}
.bg-shade {
height: 100vh;
background-color: rgba(0,0,0,0.6);
}
NETFLIX-INDEX.JSX:
import './netflix-index.css';
import { NextflixHeader } from
'../netflix-header/netflix-header';
import { NetflixMain } from
'../netflix-main/netflix-main';
NETFLIX MAIN
NETFLIX MAIN.CSS
main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 400px;
color:white;
}
.main-title {
font-size: 40px;
font-weight: bold;
font-family: Arial;
}
.main-subtitle {
font-size: 30px;
font-family: Arial;
}
NETFLIX.INDEX.JSX
8-11-2023
Syntax:
var userName = "John";
data-binding.jsx
Ex: Array
- React uses Array methods to read elements from
array and present in UI.
- Array methods used for reading all elements
a) forEach()
b) map()
c) toString()
d) join()
data-binding.jsx