BIS601 Module 3 PDF
BIS601 Module 3 PDF
MERN
Real-world Usage:
1. Declarative Views
2. Virtual DOM
React compares new Virtual DOM with old Virtual DOM → updates only
what has changed.
3. Component-Based Architecture
4. No Templates
5. Isomorphic Code
Useful for Server-Side Rendering (SSR) → better SEO and faster initial
load.
Node.js
JavaScript runtime environment (outside the browser).
Node.js Modules
Can install:
Provides:
Tools like Webpack or Browserify bundle all modules for browser use.
Example:
o Instead of waiting for a file to open, you pass a callback and move
on.
Event loop keeps checking for events and executes their callbacks.
What is Express?
Without Express, writing a full web server using pure Node.js is tedious.
Routing
Request/Response Handling
Express parses:
o URL
o Headers
o Parameters
o Set cookies
o pug
o mustache
Note: For SPAs (Single Page Applications), template engines are usually
unnecessary as the dynamic rendering happens on the client-side using
React.
What is MongoDB?
Key benefits:
Document-Oriented Storage
Example:
In RDBMS:
In MongoDB:
o One document with all invoice details and item list as nested fields.
Downsides
Schema-Less
Mongo Shell
You can:
🔹 React-Router
React-Router:
Useful for:
Fast UI development.
Alternative UI libraries:
Material-UI (MUI)
Elemental UI
🔹 Webpack
Server-side:
Client-side:
• What is Serverless?
Serverless computing allows developers to run applications without
managing servers. Cloud providers handle infrastructure, scaling, and
maintenance.
• Why Serverless?
• AWS Lambda
• Azure Functions
• Netlify Functions
• Vercel Serverless
Objective:
Tools Used:
React: https://unpkg.com/react@16/umd/react.development.js
ReactDOM: https://unpkg.com/react-dom@16/umd/react-dom.development.js
Step-by-Step Explanation:
Save it as index.html.
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-
dom.development.js"></script>
<div id="content"></div>
);
ReactDOM.render(element, document.getElementById('content'));
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script
src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-
dom.development.js"></script>
</head>
<body>
<div id="content"></div>
<script>
ReactDOM.render(element, document.getElementById('content'));
</script>
</body>
</html>
Output:
What is Node.js?
Steps:
Install nvm
node -v
What is npm?
mkdir issuetracker
cd issuetracker
Initialize with npm:
npm init -y
What is Express?
To install Express:
4. Understanding package.json
What is package.json?
Key Fields:
Steps in code:
app.use(express.static('public'));
app.listen(PORT, () => {
});
Output
React Components
🔹 Why Use React Components?
Components:
o React to user input, manage state, and interact with each other.
🔸 Features:
Edit/update issues.
Delete issues.
🔸 Attributes of an Issue:
React Classes
Purpose:
render() {
return (
<h1>{message}</h1>
</div>
);
Instantiate a component:
ReactDOM.render(element, document.getElementById('contents'));
Important Notes:
Example
render() {
render() {
Example:
render() {
Example:
ReactDOM.render(element, document.getElementById('contents'));
Instead of writing all this logic in one component, we create three smaller
components:
render() {
render() {
render() {
render() {
return (
<>
<h1>Issue Tracker</h1>
<IssueFilter />
<hr />
<IssueTable />
<hr />
<IssueAdd />
</>
);
ReactDOM.createRoot(document.getElementById("root")).render(
<IssueList />
);
Props (short for properties) allow you to pass data from a parent
component to a child component.
In JSX, you pass props just like HTML attributes.
In the child component, they’re accessed using this.props.
We want to render each issue (from the issue tracker) as a row in a table using a
reusable IssueRow component.
IssueTable Structure:
render() {
return (
<thead>
<tr>
<th style={rowStyle}>ID</th>
<th style={rowStyle}>Title</th>
</tr>
</thead>
<tbody>
<IssueRow
rowStyle={rowStyle}
issue_id={1}
/>
<IssueRow
rowStyle={rowStyle}
issue_id={2}
/>
</tbody>
</table>
);
}
IssueRow Component:
render() {
return (
<tr>
<td style={style}>{this.props.issue_id}</td>
<td style={style}>{this.props.issue_title}</td>
</tr>
);
Notes on JSX:
JSX does not support HTML-style comments (<!-- -->). Use JavaScript-style
comments inside {}:
Concept Overview
This allows more flexibility, especially when the data you pass is:
Any data/content placed between the opening and closing tags of a component
is accessible via this.props.children.
<CustomComponent>
</CustomComponent>
Inside CustomComponent:
render() {
return <div>{this.props.children}</div>;
render() {
return (
<div style={borderedStyle}>
{this.props.children}
</div>
);
}
Usage:
<BorderWrap>
<ExampleComponent />
</BorderWrap>
You can embed JSX or plain text within an IssueRow, like this:
<IssueRow issue_id={2}>
</IssueRow>
render() {
return (
<tr>
<td style={style}>{this.props.issue_id}</td>
<td style={style}>{this.props.issue_title}</td>
<td style={style}>{this.props.children}</td>
</tr>
);
Step-by-Step Breakdown
We store a few issue objects in a globally declared array called issues. Each
object includes various fields such as id, status, owner, effort, created, due, and
title.
const issues = [
},
},
];
Note: We left the due field undefined in one object to test optional field
rendering.
Instead of hardcoding each row, use Array.map() to transform each issue object
into an <IssueRow /> component.
);
And render it inside the table like this:
<tbody>
{issueRows}
</tbody>
You can also directly write the map expression inside JSX:
<tbody>
</tbody>
This shows that JSX allows any valid JavaScript expression inside {}.
Define a <thead> section and assign a className to the table for CSS styling.
<table className="bordered-table">
<style>
table.bordered-table th, td {
padding: 4px;
table.bordered-table {
border-collapse: collapse;
</style>
Instead of passing each field as a prop, the entire issue object is passed:
render() {
return (
<tr>
<td>{issue.id}</td>
<td>{issue.status}</td>
<td>{issue.owner}</td>
<td>{issue.created.toDateString()}</td>
<td>{issue.effort}</td>
<td>{issue.title}</td>
</tr>
);
}
Important Concepts
Concept Explanation
Object Prop Passing the entire issue object is cleaner and reduces
Passing boilerplate compared to passing each property individually.
Summary