Professional Documents
Culture Documents
proceeding:
This document is confidential and intended solely for the educational purpose
of RMK Group of Educational Institutions. If you have received this document
through email in error, please notify the system manager. This document
contains proprietary information and is intended only to the respective group /
learning community as intended. If you are not the addressee you should not
disseminate, distribute or copy through e-mail. Please notify the sender
immediately by e-mail if you have received this document by mistake and
delete this document from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any action in
reliance on the contents of this information is strictly prohibited.
22IT403
WEB DEVELOPMENT FRAMEWORKS (REACT)
Dr. S. RADHIKA,
Professor-IT, RMKEC
4
1. CONTENTS
1 Contents 5
2 Course Objectives 6
7
3 Pre Requisites
4 Syllabus 8
5 Course Outcomes 11
7 Lecture Plan 13
9 Lecture Notes 15
10 Assignments 115
6
4. Syllabus
WEB DEVELOPMENT FRAMEWORKS (React) L P T C
22IT403
(Theory Course with Laboratory Component) 3 2 0 4
OBJECTIVES:
∙ To understand web semantics and related tools and framework
∙ Able to get hands on latest JS based web frameworks
∙ To develop a scalable and responsive web application
∙ To develop an industry ready application web enterprise feature
1) Create a JS Object for Bank Account (w attributes like à customer name, account type, balance, data of
creation, bank name, branch name, pan card number). Using JS Object keyword, try to perform following
activities
List down all the entries of the bank object
Check the existence of a key
If key found, get the value for the key
Spread Operator
Merge Customer and Account Arrays
Update the Customer Object with the new values
Develop a function that takes an Spread Argument and calculates total balance.
2) Create a list of Bank Objects (same kind of object you used in above lab, but in a array format)
4) Develop a React application that has User Registration Form w field level validations, data submission to a
rest api end point, boot strap for responsive.
Use YUP or Formik to implement the same
5) Employ back end api for Login Page functionality (authentication). Post login, store the user context
(received from the back end server) in browser’s session storage as objects. And use the same as creds
during protected route verification
On the dashboard page, have a grid of Students. The data has to be bought from back end api
Employ useref, useeffect & usestate, and useHistory
Enable Exception Handling
Enable HOC and Aux Components
Implement React-Testing Library
CO1: Personalize web pages using text formatting, graphics, audio, and
video. CO2: Hands on knowledge on Rest API , propTypes
CO3: Able to develop a web application using latest React Framework
CO4: Apply various React features including functions, components, and
services. CO5: Able to develop application using ReactJs hooks .
TEXT BOOKS:
1. JAVASCRIPT THE DEFINITIVE GUIDE 7/ED Paperback – 15 June 2020
2. Full-Stack React, TypeScript, and Node: Build cloud-ready web
applications using React 17 with Hooks and GraphQL Paperback
– Import, 18 December 2020
3. Advanced Web Development with React Paperback – 1 January 2020
REFERENCES:
1. CodePen,
2. CodeSandbox (ß Preferred)
3. Stackblitz.
5. Course Outcomes
K6 Evaluation
K5 Synthesis
K4 Analysis
K3 Application
K2 Comprehension
K1 Knowledge
11
6. CO-PO/PSO
Mapping
CO PROGRAM OUTCOMES PSO
CO ATTAI P P
PO PO PO PO PO PO PO PO PO PO PO PO PS S S
NMENT O O
1 2 3 4 5 6 7 8 9 1 1 12 O
1 2 3
0 1
CO1 1 3 3 3 1 1 1 - - 2 1 2 1 - - -
CO2 2 3 2 3 1 2 1 - - 2 1 2 1 - - -
CO3 3 3 3 3 1 2 1 - 1 2 1 2 1 - - -
CO4 4 3 3 3 1 2 1 - - 2 1 2 1 - - -
CO5 5 3 3 3 1 2 1 - 1 2 1 2 1 - - -
CO 3 3 3 1 2 1 - 1 2 1 2 1 - - -
12
Lecture
Notes
Unit IV - REACT LIBRARY - I
The basic idea is that the game will present the user with a grid of randomly
appearing balloons, and the objective is to pop them to earn points. Each
successful balloon pop will reward the player with five points:
Check out this live CodePen demo to preview what you will build. Or, explore the
complete code from the GitHub repo of this project.
EVENT BUBBLEUP
In React, events can be "bubbled up" from child components to parent components. This means
that when an event occurs in a child component, it can be captured and handled by a parent
component. This behavior allows you to create complex interactions by defining event handlers at
various levels of your component tree.
For example, you might have a parent component that renders multiple child components, and you
want to handle a specific event that occurs in one of those child components at the parent level.
You can achieve this by defining an event handler in the parent component and passing it down to
the child component as a prop. When the event occurs in the child component, it can trigger the
event handler, which is defined in the parent component.
```javascript
import React from 'react';
function ChildComponent(props) {
return (
<button onClick={props.onClick}>Click me</button>
);
}
function ParentComponent() {
const handleButtonClick = () => {
alert('Button clicked in child component');
};
return (
<div>
<h1>Parent Component</h1>
<ChildComponent onClick={handleButtonClick} />
</div>
);
}
In this example, when you click the "Click me" button in the `ChildComponent`, the event bubbles
up to the `ParentComponent`, which handles the event by showing an alert.
This is a fundamental aspect of how React's component architecture and event handling work,
allowing you to create interactive and dynamic user interfaces.
Component Wrapper
In React and other component-based frameworks, a "Component Wrapper" is not a standard or
predefined term. However, the concept you might be referring to is commonly known as a "Higher-
Order Component" (HOC) or a "Wrapper Component."
A Higher-Order Component (HOC) is a pattern in React where you can create a new component
that wraps another component. This higher-order component enhances or modifies the behavior of
the wrapped component. HOCs are often used for tasks like code reuse, state management, or
adding additional props to a component.
```jsx
import React from 'react';
componentDidMount() {
// Simulate authentication logic
setTimeout(() => {
this.setState({ loggedIn: true });
}, 2000);
}
render() {
// Pass the "loggedIn" prop to the wrapped component
return <WrappedComponent {...this.props} loggedIn={this.state.loggedIn} />;
}
};
};
In this example, `withAuth` is a higher-order component that wraps the `Profile` component. It
adds a `loggedIn` prop to the `Profile` component based on some authentication logic.
You can use higher-order components to encapsulate common functionality and apply it to multiple
components in your application, which promotes code reuse and maintainability.
So, when you mention a "Component Wrapper," it's likely you are referring to this concept of a
higher-order component or a similar pattern where one component wraps another to provide
additional functionality or behavior.
Integration of CSS Modules
CSS Modules are a popular way to encapsulate CSS styles in a modular and scoped manner when
building applications with frameworks like React. They help prevent style conflicts and make it
easier to maintain and organize your styles. Here's how you can integrate CSS Modules into your
React application:
To use CSS Modules in a React project, you'll typically need to install a build tool like Webpack and
the appropriate loaders. Here's an example using npm:
```bash
npm install --save-dev css-loader style-loader
```
These loaders are commonly used with Webpack to process CSS files and enable CSS Modules.
If you haven't set up Webpack in your React project, you'll need to create or update your Webpack
configuration to include the CSS Modules configuration. Here's a simplified example:
```javascript
// webpack.config.js
module.exports = {
// ...
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[name] [local]__[hash:base64:5]', // Customize the class name
format
},
},
},
],
},
],
},
// ...
};
```
In this example, we're using the `css-loader` with the `modules` option to enable CSS Modules.
The `localIdentName` option allows you to customize the format of the generated class names.
In your project directory, create CSS files with the `.module.css` extension. For example,
`App.module.css`:
```css
/* App.module.css */
.header {
background-color: lightblue;
}
.button {
background-color: lightgreen;
}
```
Now, you can import and use CSS Modules in your React components:
```jsx
// App.js
import React from 'react';
import styles from './App.module.css'; // Import the CSS Module
function App() {
return (
<div>
<header className={styles.header}>Header</header>
<button className={styles.button}>Click me</button>
</div>
);
}
In this example, we import the styles from `App.module.css` and use them as object properties.
These properties contain the generated class names, ensuring that styles are scoped to the
component.
That's the basic integration of CSS Modules into a React project. With this setup, you can create
modular and scoped CSS styles for your React components, making it easier to manage styles in
larger applications without worrying about global conflicts.
Form validation is an essential part of building web forms, ensuring that user input is accurate and
meets specific criteria. There are several libraries and approaches you can use for form validation
in JavaScript and React. Three popular options are YUP, Formik, and standard React form
validation techniques:
1. Yup :
Yup is a schema validation library often used with Formik to handle form validation in React
applications. It provides a simple and declarative way to define validation schemas and validate
data.
Installation :
```bash
npm install yup formik
# or
yarn add yup formik
```
Usage :
```javascript
import * as Yup from 'yup';
```javascript
import { Formik, Form, Field, ErrorMessage } from 'formik';
function MyForm() {
return (
<Formik
initialValues={{ name: '', email: '' }}
validationSchema={validationSchema}
onSubmit={(values) => {
// Handle form submission here
}}
>
<Form>
<div>
<label>Name</label>
<Field type="text" name="name" />
<ErrorMessage name="name" />
</div>
<div>
<label>Email</label>
<Field type="email" name="email" />
<ErrorMessage name="email" />
</div>
<button type="submit">Submit</button>
</Form>
</Formik>
);
}
```
2. Formik:
Formik is a form library for React that simplifies form handling, including form validation, form
submission, and form state management.
Installation :
Usage :
Formik handles form validation, state, and submission, as demonstrated in the previous example.
You can also perform form validation in React without external libraries by using controlled
components and managing validation logic manually. Here's an example:
```javascript
import React, { useState } from 'react';
function MyForm() {
const [formData, setFormData] = useState({ name: '', email: '' });
const [errors, setErrors] = useState({});
if (Object.keys(newErrors).length === 0) {
// Form data is valid; proceed with submission
}
};
return (
<form onSubmit={handleSubmit}>
<div>
<label>Name</label>
<input type="text" name="name" value={formData.name} onChange={handleChange} />
{errors.name && <div>{errors.name}</div>}
</div>
<div>
<label>Email</label>
<input type="email" name="email" value={formData.email} onChange={handleChange}
/>
{errors.email && <div>{errors.email}</div>}
</div>
<button type="submit">Submit</button>
</form>
);
}
```
In this example, we manage form state (`formData`) and validation errors (`errors`) manually
using React's state and event handling.
Each of these approaches has its advantages, and the choice depends on your specific project
requirements and preferences. YUP and Formik offer a more structured and declarative way to
handle validation, while standard React validation gives you full control but requires more manual
work.
Event handling is a crucial aspect of web development, allowing you to capture and respond to
user interactions with a web page. In this explanation, I'll provide a detailed overview of event
handling in JavaScript, including examples for common events.
EVENT BASICS
-An event is a signal that something has happened, such as a user clicking a button, moving the
mouse, or pressing a key.
- Event handling involves writing code (event handlers) to respond to these events.
In this example, we'll attach a click event listener to a button element and display an alert when
the button is clicked.
```html
<!DOCTYPE html>
<html>
<body>
<button id="myButton">Click Me</button>
<script>
// Get the button element by its ID
const button = document.getElementById("myButton");
In this example, we'll use the `mouseover` and `mouseout` events to change the background
color of a div when the mouse enters and leaves it.
```html
<!DOCTYPE html>
<html>
<style>
#myDiv {
width: 100px;
height: 100px;
background-color: lightblue;
}
</style>
<body>
<div id="myDiv">Hover over me</div>
<script>
const div = document.getElementById("myDiv");
div.addEventListener("mouseover", function () {
div.style.backgroundColor = "lightgreen";
});
div.addEventListener("mouseout", function () {
div.style.backgroundColor = "lightblue";
});
</script>
</body>
</html>
```
In this example, we'll use the `keydown` event to change the text of a paragraph based on the
key pressed.
```html
<!DOCTYPE html>
<html>
<body>
<p id="myParagraph">Press a key.</p>
<script>
const paragraph = document.getElementById("myParagraph");
These examples demonstrate the basic principles of event handling in JavaScript. You can attach
event listeners to various DOM elements and respond to a wide range of events, allowing you to
create interactive and dynamic web applications. Event handling is an essential part of web
development and is used extensively to build user-friendly interfaces.
DATA BINDING
Data binding is a fundamental concept in web development, especially in the context of front-end
frameworks like Angular, React, and Vue.js. It refers to the process of establishing a connection or
synchronization between the user interface (UI) and the underlying data model. Data binding
ensures that changes in one of these components (UI or data) are automatically reflected in the
other without requiring manual updates. There are two main types of data binding:
One-way data binding means that data flows in one direction: from the data source to the UI.
When the data changes, the UI is updated to reflect those changes, but changes in the UI don't
affect the data source. Here's an example:
```html
<!-- HTML template -->
<p>{{ message }}</p>
In this example, the value of `message` in the data model is displayed in the paragraph
element. If you were to update `data.message`, the paragraph's text would automatically update
to reflect the change.
Two-way data binding allows data to flow in both directions: from the data source to the UI and
from the UI back to the data source. Changes in the UI are synchronized with the data model, and
changes in the data model are reflected in the UI. This type of binding is commonly used in form
elements. Here's an example using Angular:
```html
<!-- HTML template -->
<input [(ngModel)]="name" />
@Component({
selector: "app-root",
template: `
<input [(ngModel)]="name" />
<p>Hello, {{ name }}</p>
`,
})
export class AppComponent {
name = "John";
}
</script>
```
In this example, the `[(ngModel)]` syntax allows you to bind the input field's value (`name`) to
the data model and vice versa. If you change the input field's value, the `name` variable is
updated, and if you update `name`, the input field reflects the change.
The specific implementation and syntax of data binding can vary depending on the framework or
library you are using. Angular, for instance, has its own way of handling data binding, as
demonstrated in the example above. React typically uses one-way data binding, and Vue.js
provides a combination of both one-way and two-way data binding depending on how you
structure your components.
Overall, data binding is a powerful concept that simplifies the development of interactive web
applications by automating the synchronization of data and the user interface. The choice of one-
way or two-way data binding often depends on the requirements of your application and the
framework you are using.
16. ASSESSMENT SCHEDULE
Tentative schedule for the Assessment During 2023-2024 Odd
semester
TEXT BOOKS:
REFERENCES:
The Road to Learn React: Your journey to master plain yet pragmatic React.js by Robin
Wieruch
Learning React: Functional Web Development with React and Redux by Alex Banks and
Eve Porcello
Stefanov
CodePen,
CodeSandbox (ß
Preferred) Stackblitz.
18. MINI PROJECT SUGGESTION
An e-commerce website built using React and Typescript, where we can filter
clothes products using their customer preferred sizes as M, L or XL etc. We have
a button called “Add to cart” below each product shown on the web page, once
user selects any product, it will go to cart. At the end it can be used to
checkout. These terms must be familiar to everyone now-a-days since it tries to
mock popular e-commerce websites like Amazon, Flipkart and Myntra etc.
Event Bubbling:
Component Wrapper:
React applications.
Events Handling:
13. How can you prevent the default behavior of an event in JavaScript?
You can prevent the default behavior of an event using the
`event.preventDefault()` method.
Data Binding:
Event Bubbling:
7.What is the default behavior of an event in JavaScript when it reaches the top-level
document element?
The default behavior is that events bubble up from the target element to the
top- level document element (HTML or document), unless explicitly stopped.
18. How can you add event listeners during the capturing phase in JavaScript?
You can add event listeners during the capturing phase by passing `true` as
the third parameter to the `addEventListener` method.
Component Wrapper:
20. In React, what is the main advantage of using component wrappers (HOCs)?
The main advantage is the ability to share and reuse behavior and state
logic among multiple components without duplicating code.
1.Provide an example scenario where you might use a component wrapper in a React
application.
Integration of CSS Modules:
22. How do CSS Modules help avoid naming conflicts in CSS styles?
CSS Modules generate unique class names for each component, ensuring
that styles don't clash with styles from other components.
23. What is the naming convention for CSS Modules class names?
The naming convention typically includes a combination of the original class
name, a hash, and component-specific information to make it unique.
Events Handling:
Data Binding:
28. In two-way data binding, how are changes in the UI propagated back to the data
model?
Changes in the UI are automatically reflected in the data model,
30. How does data binding enhance the user experience in web applications?
Data binding enhances the user experience by providing real-time updates to
the UI based on changes in the underlying data, creating dynamic and interactive
web applications.
These questions provide further insight into event handling, component wrappers,
CSS Modules, form validations, event handling, and data binding in web
development.
PART B - QUESTIONS
Q. Questions CO K Level
No. Level
https://dev.to/franciscomendes10866/react-form-validation-with-formik-and-yup-3676
3) For the demo, you will build a basic registration form with validations and
basic CSS styling (see the image below) nothing too fancy.
Prerequisites
Before we dive into the implementation, let’s ensure we have everything set up correctly.
To follow along with this tutorial, you’ll need the following:
Basic knowledge of React and TypeScript.
A working React project with TypeScript support.
Installation of required dependencies:
React: ^16.8.0 or later
Formik: ^2.2.0 or later
Yup: ^0.32.1 or later
https://olaishola.medium.com/mastering-form-validation-in-react-with-formik
-and-yup-with-typescript-9dc4b3885538
4) GitHub User Search
In this project, you will use an input's value to search for users in GitHub using their
username or email.
How to build it
❑ You will first store the value typed into the input in a state value called query. After
that, you will perform an HTTP request to a GitHub API endpoint to then fetch the
users' profile which once again uses the browser fetch API. The request URL will use
the input value.
❑ Once the results are fetched, we'll see how to display all the relevant info such as
their name, avatar, and a link to go to their profile.
❑ A good way to extend this project would be to attempt to allow search functionality as
the user types instead of having to submit the form first. Make sure to use a
debounce function to ensure that you do not too many requests to the GitHub API
and get a 429 error response (too many requests)
5) A news app
This allows users to browse articles from various sources and save their favorites for later.
This project can be implemented using React and the NewsAPI to fetch news articles. To
show the list of articles, students can use the useEffect hook to fetch the data when the
component mounts and the Javascript map method to render a list of article items. To allow
users to select a source, students can use the useState hook to store the selected source in
the component’s state and render a dropdown menu with the available sources. To save an
article, students can use the useContext hook and the Context API to create a context for
storing and updating the list of favorite articles.
14. MINI PROJECT SUGGESTION
1) E-COMMERCE SITE
An e-commerce site allows users to browse and search for products, add them to a cart,
and check out using a dummy payment system. To build this app, you can create
a Product component that represents a single product and a ProductList component that
contains a list of Product components. The Product component should accept information
about the product, such as its name, price, and image, and render it along with a Add to
cart button. The ProductList component should accept an array of products and render
a Product component for each. You can also create a Cart component that displays the
items in the user’s cart and allows them to remove items or check out.
3) WEATHER APP
A weather app shows the current weather for a given location. To build this app, you can
use the OpenWeatherMap API to fetch weather data for a given location. You can then
create a Weather component that accepts a location and displays the current temperature,
humidity, and other relevant information for that location. You can also add a search form
that allows users to enter a location and see the current weather for that location.
4) A RECIPE APP
A recipe app allows users to search for recipes and save their favorites. To build this app,
you can use the Spoonacular API to fetch recipe data. You can then create
a Recipe component representing a single recipe and a RecipeList component containing a
list of Recipe components. The Recipe component should accept information about the
recipe, such as its name, ingredients, and instructions, and render this information
user-friendly. The RecipeList component should accept an array of recipes and render
a Recipe component for each. You can also add a search form that allows users to enter a
keyword and see a list of matching recipes.
Disclaimer:
This document is confidential and intended solely for the educational purpose of RMK Group of
Educational Institutions. If you have received this document through email in error, please notify the
system manager. This document contains proprietary information and is intended only to the
respective group / learning community as intended. If you are not the addressee you should not
disseminate, distribute or copy through e-mail. Please notify the sender immediately by e-mail if you
have received this document by mistake and delete this document from your system. If you are not
the intended recipient you are notified that disclosing, copying, distributing or taking any action in
relianceon the contentsof this information is strictlyprohibited.