React Js Lab Final
React Js Lab Final
Submitted by
Name: ……….…………………..……………..
Submitted by
BONAFIDE CERTIFICATE
This is to certify that this record is the bonafide record of work done by Mr./Ms.
during the academic year 2022 – 2023.
Dr.T.Latha Maheswari
Dr. V.Vijeyakaveri /
Name of the Faculty
Dr. P.Mohankumar
Dr.D.Rasi
Range of Marks
Criteria Below
Excellent Good Average
Average
Objective & Description
with sample data (20)
18-20 17-18 15-16 0-14
Page
Ex.No Name of the Experiment No. Marks Signature
Components EX1 EX2 EX3 EX4 EX5 EX6 EX7 EX8 EX9 EX10
Objective &
Description with
sample data
(20 Marks)
Formation of
Program
(30 Marks)
Execution and
Testing
(30 Marks)
Documentation
(10 Marks)
Viva
(10 Marks)
TOTAL
AVERAGE
Consolidated Mark (100)
Faculty Signature
1.a)Study of React Installation and Terminal Commands
Objective
React app:
1
1.b) Demonstration of a Stateless Functional Component
Objective
Description
A React functional component is a simple JavaScript function that accepts props and returns a
React element. After the introduction of React Hooks, writing functional components has become
the standard way of writing React components in modern applications.
Algorithm
1. Create the new js file name it as fcomponent.js.
2. Create the new function component and name it as demo in fcomponent.
3. Inside the function componentreturn the html element.
4. And export the function component demo.
5. Now import the function component from fcomponent file.
6. Inside the root.render use the component.
7. Now the output will display in the react app.
Program
fcomponent.js:
import React from 'react'
function demo() {
return(
<div>
<h1>Hello everyone, Welcome to react.</h1>
</div>
)
}
export default demo
Index.js:
import React from 'react';
import ReactDOM from 'react-dom/client';
import Fcomponent from './fcomponent';
const root = ReactDOM.createRoot(document.getElementById('root'));
2
root.render(
<React.StrictMode>
<Fcomponent/>
</React.StrictMode>
);
Sample Output
Result
Thus the function component is successfully implemented.
3
2. Demonstration of a Statefull Class Component
Objective
Description
A class component is a more featured way to define a React component. It also acts like a
function that receives props. The component has to include the extends React.Component
statement, this statement creates an inheritance to React.Component, and gives your component
access to React.Component's functions.The component also requires a render() method, this
method returns HTML
Algorithm
1.Create the new js file name it as ccomponent.js.
2.Create the new function component and name it as Demo in ccomponent.
3.Inside the render function of the class componentDemo return the html element.
4.And export the class component Demo.
5. Now import the class component from ccomponent file.
6.Inside the root.render use the component.
7.Now the output will display in the react app.
Program
ccomponent.js:
import React from 'react'
class Ccomponent extends React.Component {
state = { }
render() {
return (
<div>
<h1>Class Component:</h1>
<h2>Hello Everyone,Welcome To React</h2>
</div>
);
}
}
export default Ccomponent;
4
Index.js:
import React from 'react';
import ReactDOM from 'react-dom/client';
import Ccomponent from './ccomponent';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<Ccomponent/>
</React.StrictMode>
);
Sample Output
Result
Thus the Class component is successfully implemented.
5
3. Implementation of Conditional Rendering using Class Component
Objective
Description
A conditional rendering is a piece of content that is displayed or rendered when a
predefined condition is met. You can use conditional renderings to control the way visitors view
and interact with your website.
Algorithm
1.Create the new js file name it as conditionalrendering.js.
2.Create the new function component and name it as Demo in conditionalrendering.
3.Create three functions,changeColor1, changeColor2 ,changeCount for changing colors
of the Buttons and text.
4.Inside the render function of the class componentreturn the html Button elements.
5.And export the class component Conditionalrendering
6. Now import the class component from conditionalrendering file.
7.Inside the root.render use the component.
8.Now the output will display in the react app.
Program
conditionalrendering.js:
7
Index.js:
import React from 'react';
import ReactDOM from 'react-dom/client';
import Conditional from './conditional';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<Conditional/>
</React.StrictMode>);
Sample Output
Result:
Thus the conditional rendering is successfully implemented.
8
4.Implementation of Communication between Parent and child Components
Objective
Description
In React parent components can communicate to child components using a special
property defined by React called as Props. All the components in React will be having this proper
defined by default which will hold all the properties as key value pairs that are sent from the
parent component.
Algorithm
1.Create the new js file names them as parent.js,child.js.
2.Create the new class component and name it as Child in child.js and return the html
elements..
3.Inside the render function of the class componentit should return the html element.
4.And export the class component Child.
5. Now import the class component from child file.
6.Inside the render function of the parent’s class component it should return the child
component
7.Now the output will display in the react app.
Program
parent.js:
import React from 'react';
import Child from './child';
class Parent extends React.Component{
state = {
name: "",
}
handleCallback = (childData) =>{
this.setState({name: childData})
}
render(){
const {name} = this.state;
return(
<div style={{textAlign:'center'}}>
9
<h1>Child and Parent Components</h1>
<Child parentCallback = {this.handleCallback}/>
{name}
</div>
)
}
}
export default Parent;
Child.js:
render(){
return(
<div>
<form onSubmit = {this.onTrigger}>
<input type = "text"
name = "myname" placeholder = "Enter Name"/>
<br></br><br></br>
<input type = "submit" value = "Submit"/>
<br></br><br></br>
</form>
</div>
)
}
}
export default Child
Index.js:
import React from 'react';
import ReactDOM from 'react-dom/client';
import Parent from './parentchild';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<Parentt/>
</React.StrictMode>
);
10
Sample Output
Result:
Thus the conditional rendering is successfully implemented.
11
5. Create material UI Card using React
Objective
Description
A react card component is a content container. It incorporates options for images, headers, and
footers, a wide variety of content, contextual background colors, and excellent display options.
Algorithm
Program
12
return (
<CardMedia
component="img"
height="140"
image="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/EBnda3IIUzAJDMXe9
0eQQqbmJJyyw5uaqPyjJYna8yYStYSTmNCA+agBA+EsBXjrWNR0VxSpiJqlAODLDgubLLU
o1vHdFxb9CHlUqXubGSaJ5DygjhNkonoClKUChbhm+HIqrg6iA8nEpDB/A7o1HR+ozCu938Ij
mTMIp82Ckl+ /rjE3wp5woUA1wVtTHRbthQoZPY2ZeI4UKGhM//2Q=="
alt="green iguana"
/>
<CardContent>
SKCET
</Typography>
SKCET is one of the finest colleges in South India.It is well known for it's infrastructure,
academics and the placements offered. With Asia's second-largest library, SKCET is well -known
for it's architecture and maintenance.
</Typography>
</CardContent>
<CardActions>
<Button size="small">Share</Button>
</CardActions>
</Card>
);
}
13
Sample Output:
RESULT
14
6. Design a Custom Navigation bar using React
Objective
Description
Bootstrap navbar is a horizontal navigation component which apart from traditional, text links,
might embed icons, dropdowns, avatars or search forms.
Algorithm
Program
15
import Avatar from '@mui/material/Avatar';
function ResponsiveAppBar() {
setAnchorElNav(event.currentTarget);
};
setAnchorElUser(event.currentTarget);
};
setAnchorElNav(null);
};
setAnchorElUser(null);
};
16
return (
<AppBar position="static">
<Container maxWidth="xl">
<Toolbar disableGutters>
<Typography
variant="h6" noWrap
component="a"
2,
fontFamily: 'monospace',
'.3rem', color:
'inherit', textDecoration:
'none',
}}
>
SKCET
</Typography>
<IconButton
size="large"
17
aria-controls="menu-appbar" ariahaspopup="true"
onClick={handleOpenNavMenu} color="inherit"
>
<MenuIcon />
</IconButton>
<Menu id="menuappbar"
anchorEl={anchorElNav}
anchorOrigin={{ vertical:
'bottom', horizontal:
'left',
}}
keepMounted
transformOrigin={{ vertical:
'top', horizontal:
'left',
}}
open={Boolean(anchorElNav)}
md: 'none' },
}}
>
{pages.map((page) => (
<Typography textAlign="center">{page}</Typography>
</MenuItem>
))}
18
</Menu>
</Box>
<Typography
variant="h5" noWrap
component="a"
2,
'.3rem',
color: 'inherit',
textDecoration: 'none',
}}
>
SKCET
</Typography>
{pages.map((page) => (
<Button
key={page}
onClick={handleCloseNavMenu}
>
{page}
19
</Button>
))}
</Box>
</IconButton>
</Tooltip>
'45px' }} id="menuappbar"
anchorEl={anchorElUser}
anchorOrigin={{ vertical:
}}
keepMounted
transformOrigin={{ vertical:
'top', horizontal:
'right',
}}
open={Boolean(anchorElUser)}
onClose={handleCloseUserMenu}
>
{settings.map((setting) => (
20
<Typography textAlign="center">{setting}</Typography>
</MenuItem>
))}
</Menu>
</Box>
</Toolbar>
</Container>
</AppBar>
);
App.js
import './style.css';
function App(){
return(
<ResponsiveAppBar/>
);
21
export default App
Output
Result
22
7.Implementation of React component to handle HTTP requests
Objective
Description
Most useful React applications involve interacting with a server to load and persist data. To do
this on the web, we use HTTP requests with the browser’s built-in fetch API (or you may use
some other open source library that’s built on top of this API).
Algorithm
Program
fetch.js:
useEffect(() => {
fetch('https://jsonplaceholder.typicode.com/users')
})
23
console.log(user)
return(
<div className="main">
{user.map(u => (
))}
</div>
App.js:
import './App.css';
function App() {
return (<>
<FetchAPI />
</>);
24
Output
Result
25
8. Implementation of Drop-down Component using React
Objective:
To implement a Drop-down component using React.
Algorithm
Coding:
App.js
Dropdown.css
.dropdown-container {
text-align: left;
border: 2px solid rgb(57, 19, 196);
position: relative;
border-radius: 5px;
}
26
.dropdown-input {
padding: 20px;
display: flex;
align-items: center;
justify-content: space-between;
user-select: none;
}
Dropdown.js
Output:
Result:
Objective
Algorithm
App.js
import './mainpage.css';
import './returnpage.css';
import Mainpage from './mainpage'
import Returnpage from './returnpage'
28
App.test.js
Index.css
body {
margin: 0;
padding: 0;
font-family: sans-serif;
height: 100%;
}
Index.js
ReactDOM.render(
<App />,
document.getElementById('root')
);
29
Mainpage.js
//import React from 'react';
import "./mainpage.css"
import "./returnpage.css"
import { Link } from "react-router-dom";
</div>
</>
);
};
export default Mainpage;
mainpage.css
.v2_21 {
top: 100px;
left: 50vh;
position: absolute;
font-family: Inter;
font-weight: Bold;
font-size: 30px;
text-align: center;
}
Returnpage.js
import "./mainpage.css"
import "./returnpage.css"
import { Link } from "react-router-dom";
</div>
</>
);
};
export default Returnpage;
30
returnpage.css
.v2_21 {
top: 100px;
left: 50vh;
position: absolute;
font-family: Inter;
font-weight: Bold;
font-size: 30px;
text-align: center;
}
31
Output:
Result:
Objective:
Algorithm:
33
Coding:
};
handleChange(e) {
let fields = this.state.fields; fields[e.target.name] = e.target.value; this.setState({
fields
});
}
submituserRegistrationForm(e) { e.preventDefault();
if (this.validateForm()) { let fields = {}; fields["username"] = "";
fields["mobileno"] = "";
fields["password"] = ""; this.setState({fields:fields}); alert("Form submitted");
}
validateForm() {
App.js
import './App.css';
import RegisterForm from '.form'; function App() {
return (
<div className="App">
<RegisterForm/>
</div>
);
}
export default App;
CSS
#register, #login {
width: 300px;
border: 1px solid #d6d7da; padding: 0px 15px 15px 15px; border-radius: 5px;
font-family: arial; line-height: 16px; color: #333333; font-size: 14px;
background: #ffffff; margin: 100px auto;
}
.button {
background-color: #00BFFF; border-color: #3ac162; font-weight: bold; padding: 12px 15px;
color: #ffffff;
}
Result:
37