Reactjs Lab Manual 6th Sem
Reactjs Lab Manual 6th Sem
REACTJS
Lab Manual
(SubjectCode:BCSL657B)
[As per Choice Based Credit System (CBCS) scheme]
SEMESTER–VI
PREPAREDBY,
Mr. Giridhar Gowda (Sr.Asst Professor)
APPROVEDBY,
Dr.Manjunath Kotari(Professor and Head of CSE)
COURSEOUTCOMES(CO’S)
Co Course outcomes Blooms Target
Numbers level level
Construct a real time web application using
stateful component and props with
BCSL657B.1 parent , child components.. Apply(L2) 2
Develop a Counter application that
demonstrates state management with
BCSL657B.2 useState hook and To-do list application Apply(L2) 2
using React functional components
Build React application that demonstrates
component composition, props and React
BCSL657B.3 Apply(L2) 2
form to validate user information.
Design ProfileCard component to display
the user’s profile information and
Reminder application that dynamically
BCSL657B.4 effects the application based on props or Apply(L2) 2
state.
Demonstrate routing and class-based
BCSL657B.5 component concept for implementing Apply(L2) 2
dynamic web application.
BCSL657B.2 2 1 2 2 2 2 2 2 2 2 2 2
BCSL657B.3 2 1 2 2 2 2 2 2 2 2 2 2
BCSL657B.4
2 1 2 2 2 2 2 2 2 3 3 2
BCSL657B.5 2 1 2 2 2 2 2 2 2 3 3 2
Avg 2.0 1.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.4 2.4 2.0
REACTJS LAB
REACTJS Semester 6
Course Code BCSL657B CIE Marks 50
Teaching Hours/Week(L:T:P:S) 0:0:1:0 SEE Marks 50
Credits 01 Exam 2
Hours
Examination type(SEE) Practical
Course objectives:
● Enable students to develop React applications utilizing functional and class-based
components, effectively managing state with hooks and lifecycle methods .
● Introduce, how to pass data dynamically between parent and child components
using props, ensuring modular and reusable component design.
● Create dynamic and responsive applications, integrating forms, validation, task
management systems, and styled components.
● Use React Router for navigation, external API integration for dynamic data
handling, and CSS styling techniques for modern UI/UX design.
Sl.No Experiments
1 Use create-react-app to set up a new project. Edit the App.js file to include a stateful
component with useState. Add an input field and a element that displays text based on
the input. Dynamically update the content as the user types..
2 Develop a React application that demonstrates the use of props to pass data from a
parent component to child components. The application should include the parent
component named App that serves as the central container for the application. Create
two separate child components, Header: Displays the application title or heading.
Footer: Displays additional information, such as copyright details or a tagline. Pass
data (e.g., title, tagline, or copyright information) from the App component to the
Header and Footer components using props. Ensure that the content displayed in the
Header and Footer components is dynamically updated based on the data received
from the parent component.
3 Create a Counter Application using React that demonstrates state management
with the useState hook. Display the current value of the counter prominently on
the screen. Add buttons to increase and decrease the counter value. Ensure the
counter updates dynamically when the buttons are clicked. Use the useState hook
to manage the counter's state within the component. Prevent the counter from
going below a specified minimum value (e.g., 0). Add a "Reset" button to set the
counter back to its initial value. Include functionality to specify a custom
increment or decrement step value.
4 Develop a To-Do List Application using React functional components that
demonstrates the use of the useState hook for state management. Create a functional
component named ToDoFunction to manage and display the todo list. Maintain a list
of tasks using state. Provide an input field for users to add new tasks. Dynamically
render the list of tasks below the input field. Ensure each task is displayed in a user-
friendly manner. Allow users to delete tasks from the list. Mark tasks as completed
or pending, and visually differentiate them.
5 Develop a React application that demonstrates component composition and the use
of props to pass data. Create two components: FigureList: A parent component
responsible for rendering multiple child components. BasicFigure: A child
component designed to display an image and its associated caption. Use the
FigureList component to dynamically render multiple BasicFigure components. Pass
image URLs and captions as props from the FigureList component to each
BasicFigure component. Style the BasicFigure components to display the image and
caption in an aesthetically pleasing manner. Arrange the BasicFigure components
within the FigureList in a grid or list format. Allow users to add or remove images
dynamically. Add hover effects or animations to the images for an interactive
experience.
6 Design and implement a React Form that collects user input for name, email, and
password. Form Fields are Name, Email, Password. Ensure all fields are filled before
allowing form submission.Validate the email field to ensure it follows the correct
email format (e.g., example@domain.com). Optionally enforce a minimum password
length or complexity. Display error messages for invalid or missing inputs. Provide
visual cues (e.g., red borders) to highlight invalid fields. Prevent form submission
until all fields pass validation. Log or display the entered data upon successful
submission (optional). Add a "Show Password" toggle for the password field.
Implement clientside sanitization to ensure clean input.
7 Develop a React Application featuring a ProfileCard component to display a user's
profile information, including their name, profile picture, and bio. The component
should demonstrate flexibility by utilizing both external CSS and inline styling for its
design. Display the following information: Profile picture, User's name, A short bio
or description Use an external CSS file for overall structure and primary styles, such
as layout, colors, and typography. Apply inline styles for dynamic or specific styling
elements, such as background colors or alignment. Design the ProfileCard to be
visually appealing and responsive. Ensure the profile picture is displayed as a circle,
and the name and bio are appropriately styled. Add hover effects or animations to
enhance interactivity. Allow the background color of the card to change dynamically
based on a prop or state
8 Develop a Reminder Application that allows users to efficiently manage their tasks.
The application should include the following functionalities: Provide a form where
users can add tasks along with due dates. The form includes task name,Due date,An
optional description. Display a list of tasks dynamically as they are added. Show
relevant details like task name, due date, and completion status. Include a filter option
to allow users to view all Tasks and Display all tasks regardless of status. Show only
tasks marked as completed. Show only tasks that are not yet completed.
9 Design a React application that demonstrates the implementation of routing using the
react-router-dom library. The application should include the Navigation Menu: Create
a navigation bar with links to three distinct pages, Home, About, Contact. Develop
separate components for each page (Home, About, and Contact) with appropriate
content to differentiate them. Configure routes using react-router-dom to render the
corresponding page component based on the selected link. Use BrowserRouter and
Route components for routing. Highlight the active link in the navigation menu to
indicate the current page
10 Design a React application featuring a class-based component that demonstrates the
use of lifecycle methods to interact with an external API. The component should fetch
and update data dynamically based on user interactions or state changes. Use the
componentDidMount lifecycle method to fetch data from an API when the
component is initially rendered. Display the fetched data in a structured format, such
as a table or list. Use the componentDidUpdate lifecycle method to detect changes in
the component's state or props. Trigger additional API calls to update the displayed
data based on user input or actions (e.g., filtering, searching, or pagination).
Implement error handling to manage issues such as failed API requests or empty data
responses. Display appropriate error messages to the user when necessary. Allow
users to perform actions like filtering, searching, or refreshing the data. Reflect
changes in the displayed data based on these interactions.
● https://www.youtube.com/watch?v=V9i3cGD-mts
● https://youtu.be/PHaECbrKgs0
● https://youtu.be/uvEAvxWvwOs
● https://www.geeksforgeeks.org/state-management-with-usestate-hook-in-react/
● https://youtu.be/KU-I2M9Jm68
● https://youtu.be/H63Pd_lXkeQ
● https://youtu.be/oTIJunBa6MA
● https://youtu.be/3EbYJrAOpUs
PROGRAM 1
Use create-react-app to set up a new project. Edit the App.js file to include a stateful
component with useState. Add an input field and a element that displays text based on
the input. Dynamically update the content as the user types..
function App() {
const [inputText, setInputText] = useState('');
return (
<div>
<input
type="text"
value={inputText}
onChange={handleChange}
placeholder="Type something..."
/>
<h1>{inputText}</h1>
</div>
);
}
OUTPUT :
AIET MUDABIDRE
AIETMUDABIDRE
PROGRAM 2
Develop a React application that demonstrates the use of props to pass data from a parent
component to child components. The application should include the parent component
named App that serves as the central container for the application. Create two separate
child components, Header: Displays the application title or heading. Footer: Displays
additional information, such as copyright details or a tagline. Pass data (e.g., title, tagline,
or copyright information) from the App component to the Header and Footer components
using props. Ensure that the content displayed in the Header and Footer components is
dynamically updated based on the data received from the parent component.
// Header Component
const Header = ({ title }) => {
return (
<header className="header">
<h1>{title}</h1>
</header>
);
};
// Footer Component
const Footer = ({ copyright }) => {
return (
<footer className="footer">
<p>{copyright}</p>
</footer>
);
};
/* style.css */
.header {
text-align: center;
border: 2px solid black;
padding: 20px;
border-radius: 10px;
margin: 3rem;
width: 400px;
}
.footer {
color: green;
font-size: 10px;
OUTPUT :
ReactPropsDemo
WelcometooursimpleReactapplicationdemonstratingprops!
©2025MyReactApp.Allrights reserved.
PROGRAM 3
Create a Counter Application using React that demonstrates state management with the
useState hook. Display the current value of the counter prominently on the screen. Add
buttons to increase and decrease the counter value. Ensure the counter updates
dynamically when the buttons are clicked. Use the useState hook to manage the counter's
state within the component. Prevent the counter from going below a specified minimum
value (e.g., 0). Add a "Reset" button to set the counter back to its initial value. Include
functionality to specify a custom increment or decrement step value
return (
<div className="flex">
<div className="bg-white">
<h1 className="text-3xl">Counter App</h1>
<p className="text-4xl">{count}</p>
<div className="space">
<button onClick={increase} className="px-4 ">Increase</button>
<button onClick={decrease} className="px-6 ">Decrease</button>
<button onClick={reset} className="px-8">Reset</button>
</div>
<div>
<label className="block">Step Value:</label>
<input
type="number"
value={step}
onChange={(e) => setStep(Number(e.target.value))}
className="px-2"
/>
</div>
</div>
</div>
);
}
OUTPUT :
CounterApp
21
IncreaseDecreaseReset
StepValue:03
PROGRAM 4
Develop a To-Do List Application using React functional components that demonstrates the
use of the useState hook for state management. Create a functional component named
ToDoFunction to manage and display the todo list. Maintain a list of tasks using state. Provide
an input field for users to add new tasks. Dynamically render the list of tasks below the input
field. Ensure each task is displayed in a user-friendly manner. Allow users to delete tasks from
the list. Mark tasks as completed or pending, and visually differentiate them.
return (
<div className="p-4">
<h2 className="text-xl">To-Do List</h2>
<div className="flex">
<input
type="text"
className="border"
placeholder="Add a new task"
value={task}
onChange={(e) => setTask(e.target.value)}
/>
<button
className="bg-blue"
onClick={addTask}
>
Add
</button>
</div>
<ul>
{tasks.map((t, index) => (
<li
key={index}
className={`flex2 ${t.completed ? "line-" : "text2"}`}
>
<span onClick={() => toggleTaskCompletion(index)}>{t.text}</span>
<button
className="text1"
onClick={() => deleteTask(index)}
>
✖
</button>
</li>
))}
</ul>
</div>
);
}
OUTPUT :
To-DoList
Add a new task Add
• coding✖
• painting✖
• reading✖
PROGRAM 5
Develop a React application that demonstrates component composition and the use of props to pass
data. Create two components: FigureList: A parent component responsible for rendering multiple child
components. BasicFigure: A child component designed to display an image and its associated caption.
Use the FigureList component to dynamically render multiple BasicFigure components. Pass image
URLs and captions as props from the FigureList component to each BasicFigure component. Style the
BasicFigure components to display the image and caption in an aesthetically pleasing manner. Arrange
the BasicFigure components within the FigureList in a grid or list format. Allow users to add or remove
images dynamically. Add hover effects or animations to the images for an interactive experience.
};
return (
<div className="p-4 max-w-4xl mx-auto">
<div className="mb-4 flex gap-2">
<input
type="text"
placeholder="Image URL"
value={newImage}
onChange={(e) => setNewImage(e.target.value)}
className="p-2 border rounded w-full"
/>
<input
type="text"
placeholder="Caption"
value={newCaption}
onChange={(e) => setNewCaption(e.target.value)}
className="p-2 border rounded w-full"
/>
<button
onClick={addFigure}
className="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
>
Add
</button>
</div>
<div className="grid grid-cols-2 md:grid-cols-3 gap-4">
{figures.map((figure) => (
<BasicFigure
key={figure.id}
src={figure.src}
caption={figure.caption}
onRemove={() => removeFigure(figure.id)}
/>
))}
</div>
</div>
);
};
export default function App() {
return (
<div className="min-h-screen bg-gray-100 flex items-center justify-center">
<FigureList />
</div>
);
}
OUTPUT :
Placeholder1
Remove
Placeholder2
PROGRAM 6
Design and implement a React Form that collects user input for name, email, and password. Form
Fields are Name, Email, Password. Ensure all fields are filled before allowing form submission.Validate
the email field to ensure it follows the correct email format (e.g., example@domain.com). Optionally
enforce a minimum password length or complexity. Display error messages for invalid or missing
inputs. Provide visual cues (e.g., red borders) to highlight invalid fields. Prevent form submission until
all fields pass validation. Log or display the entered data upon successful submission (optional). Add a
"Show Password" toggle for the password field. Implement clientside sanitization to ensure clean input.
return (
<div className="max-w-md mx-auto p-6 bg-white rounded-lg shadow-md">
<h2 className="text-xl font-semibold mb-4">User Registration</h2>
<form onSubmit={handleSubmit}>
<div className="mb-4">
<label className="block mb-1">Name</label>
<input
type="text"
name="name"
value={formData.name}
onChange={handleChange}
className={`w-full p-2 border ${errors.name ? "border-red-500" : "border-gray-300"}
rounded`}
/>
{errors.name && <p className="text-red-500 text-sm">{errors.name}</p>}
</div>
<div className="mb-4">
<label className="block mb-1">Email</label>
<input
type="email"
name="email"
value={formData.email}
onChange={handleChange}
className={`w-full p-2 border ${errors.email ? "border-red-500" : "border-gray-300"}
rounded`}
/>
{errors.email && <p className="text-red-500 text-sm">{errors.email}</p>}
</div>
<div className="mb-4">
<label className="block mb-1">Password</label>
<div className="relative">
<input
type={showPassword ? "text" : "password"}
name="password"
value={formData.password}
onChange={handleChange}
className={`w-full p-2 border ${errors.password ? "border-red-500" : "border-gray-300"}
rounded`}
/>
<button
type="button"
className="absolute right-2 top-2 text-sm"
onClick={() => setShowPassword(!showPassword)}
>
{showPassword ? "Hide" : "Show"}
</button>
</div>
{errors.password && <p className="text-red-500 text-sm">{errors.password}</p>}
</div>
<button
type="submit"
className="w-full bg-blue-500 text-white p-2 rounded mt-4 hover:bg-blue-600"
>
Submit
</button>
</form>
</div>
);
};
OUTPUT :
User Registration
Name
Email
giri@gmail.com
Password
●●●●●●●● Show
Submit
PROGRAM 7
Develop a React Application featuring a ProfileCard component to display a user's profile information,
including their name, profile picture, and bio. The component should demonstrate flexibility by
utilizing both external CSS and inline styling for its design. Display the following information: Profile
picture, User's name, A short bio or description Use an external CSS file for overall structure and
primary styles, such as layout, colors, and typography. Apply inline styles for dynamic or specific
styling elements, such as background colors or alignment. Design the ProfileCard to be visually
appealing and responsive. Ensure the profile picture is displayed as a circle, and the name and bio are
appropriately styled. Add hover effects or animations to enhance interactivity. Allow the background
color of the card to change dynamically based on a prop or state.
function App() {
return (
<div className="app">
<ProfileCard
name="John Doe"
bio="Web Developer & Designer | Passionate about UI/UX"
profilePic="https://randomuser.me/api/portraits/men/75.jpg"
initialBgColor="#f3f3f3"
/>
</div>
);
}
// ProfileCard.js
return (
<div
className="profile-card"
style={{ backgroundColor: bgColor }}
onMouseEnter={handleHover}
onMouseLeave={handleHover}
>
<img src={profilePic} alt={name} className="profile-pic" />
<h2 className="profile-name">{name}</h2>
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 18
REACTJS LAB
<p className="profile-bio">{bio}</p>
</div>
);
};
// ProfileCard.css
.profile-card {
width: 300px;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
text-align: center;
transition: background-color 0.3s ease-in-out, transform 0.2s ease-in-out;
}
.profile-card:hover {
transform: scale(1.05);
}
.profile-pic {
width: 100px;
height: 100px;
border-radius: 50%;
object-fit: cover;
margin-bottom: 10px;
}
.profile-name {
font-size: 22px;
color: #333;
margin: 5px 0;
}
.profile-bio {
font-size: 16px;
color: #666;
}
OUTPUT :
John Doe
WebDeveloper&Designer|Passionate about
UI/UX
PROGRAM 8
Develop a Reminder Application that allows users to efficiently manage their tasks. The application
should include the following functionalities: Provide a form where users can add tasks along with due
dates. The form includes task name,Due date,An optional description. Display a list of tasks
dynamically as they are added. Show relevant details like task name, due date, and completion status.
Include a filter option to allow users to view all Tasks and Display all tasks regardless of status. Show
only tasks marked as completed. Show only tasks that are not yet completed.
return (
<div className="p-6 max-w-xl mx-auto bg-white rounded-xl shadow-md space-y-4">
<h1 className="text-2xl font-bold">Reminder Application</h1>
<TaskForm addTask={addTask} />
<Filter setFilter={setFilter} />
<TaskList tasks={filteredTasks} toggleTaskCompletion={toggleTaskCompletion} />
</div>
);
}
return (
<form onSubmit={handleSubmit} className="space-y-2">
<input
type="text"
placeholder="Task Name"
className="border p-2 w-full"
value={taskName}
onChange={(e) => setTaskName(e.target.value)}
required
/>
<input
type="date"
className="border p-2 w-full"
value={dueDate}
onChange={(e) => setDueDate(e.target.value)}
required
/>
<textarea
placeholder="Description (Optional)"
className="border p-2 w-full"
value={description}
onChange={(e) => setDescription(e.target.value)}
/>
<button type="submit" className="bg-blue-500 text-white px-4 py-2 rounded">
Add Task
</button>
</form>
);
}
OUTPUT :
ReminderApplication
Description
TaskName dd/mm/yyyy (Optional) Add Task
AllCompletedPending
codiing
Due: 2025-02-01
coding on reactjs
Mark Complete
reading
Due: 2025-01-30
PROGRAM 9
Design a React application that demonstrates the implementation of routing using the react-router-dom
library. The application should include the Navigation Menu: Create a navigation bar with links to
three distinct pages, Home, About, Contact. Develop separate components for each page (Home, About,
and Contact) with appropriate content to differentiate them. Configure routes using react-router-dom
to render the corresponding page component based on the selected link. Use BrowserRouter and Route
components for routing. Highlight the active link in the navigation menu to indicate the current page.
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
</Routes>
</div>
</Router>
);
};
// About.js
import React from "react";
// Contact.js
import React from "react";
// Home.js
// App.css
nav ul {
display: flex;
list-style-type: none;
gap: 20px;
}
nav ul li a {
text-decoration: none;
color: black;
padding: 5px 10px;
}
nav ul li a.active {
color: white;
background-color: blue;
border-radius: 5px;
}
OUTPUT :
PROGRAM 10
Design a React application featuring a class-based component that demonstrates the use of lifecycle
methods to interact with an external API. The component should fetch and update data dynamically
based on user interactions or state changes. Use the componentDidMount lifecycle method to fetch data
from an API when the component is initially rendered. Display the fetched data in a structured format,
such as a table or list. Use the componentDidUpdate lifecycle method to detect changes in the
component's state or props. Trigger additional API calls to update the displayed data based on user
input or actions (e.g., filtering, searching, or pagination). Implement error handling to manage issues
such as failed API requests or empty data responses. Display appropriate error messages to the user
when necessary. Allow users to perform actions like filtering, searching, or refreshing the data. Reflect
changes in the displayed data based on these interactions.
componentDidMount() {
this.fetchData();
}
componentDidUpdate(prevProps, prevState) {
if (prevState.searchQuery !== this.state.searchQuery) {
this.fetchData();
}
}
handleRefresh = () => {
this.fetchData();
};
render() {
const { data, searchQuery, error, loading } = this.state;
return (
<div>
<h2>Data Fetcher</h2>
<input
type="text"
placeholder="Search..."
value={searchQuery}
onChange={this.handleSearch}
/>
<button onClick={this.handleRefresh}>Refresh</button>
{loading && <p>Loading data...</p>}
{error && <p style={{ color: 'red' }}>{error}</p>}
<ul>
{data.length > 0 ? (
data.map(item => (
<li key={item.id}>{item.title}</li>
))
):(
<p>No data available</p>
)}
</ul>
</div>
);
}
}
OUTPUT :
Data Fetcher
Search... Refresh