SlideShare a Scribd company logo
NEXT.JS
Next.js is a flexible React framework that gives you building blocks to
create fast web applications.
1
Binumon Joseph, Assistant Professor
MASTERI
NG SERVER-SI
DE
RENDERI
NG WI
TH NEXT.JS:
A COMPREHENSIVE
TUTORIAL
Binumon Joseph, Assistant Professor 2
INTRODUCTION
Server-Side Rendering (SSR)is
a technique that allows your
web application to pre-render
HTML on a server,providing
faster load times and a better
user experience.In this tutorial,
we'll cover Next.js,a framework
for building server-rendered
React applications.
Binumon Joseph, Assistant Professor 3
WhyUseSSR?
SSR can improve SEO,performance,
and user experience. It allows search
engines to better crawl your site,
reduces the time to first paint,and
provides users with a fully rendered
page on the initial load. Next.js
simplifies the process of building
SSR applications.
Binumon Joseph, Assistant Professor 4
GETTINGSTARTEDWITHNEXT.JS
To get started with Next.js,you'll
need to install it and create a
new project.Next.js provides
several built-in features,such as
dynamic imports,automatic
code splitting,and server-side
rendering.You can also easily
add custom routes and API
endpoints.
Binumon Joseph, Assistant Professor 5
T
o build pages with Next.js,you'll
create a pages directory and add
React components for each page.
Next.js uses getI
nitialProps to
fetch data and render the page on
the server.You can also use
dynamic routing and static site
generation to optimize
performance.
BUILDINGPAGESWITHNEXT.JS
Binumon Joseph, Assistant Professor 6
Deploying
Your
Next.js
App
Next.js makes it easy to deploy
your app to Vercel,a cloud
platform for static and serverless
sites.Vercel provides automatic
SSL,custom domains,and
global CDN.You can also deploy
to other platforms such as
Heroku or AWS.
Binumon Joseph, Assistant Professor 7
DeployingYourNext.jsApp
Next.js provides a powerful framework for building
server-rendered React applications. By using SSR,
you can improve SEO, performance, and user
experience. With Next.js, you can easily create
dynamic routes, API endpoints, and deploy your app
to the cloud. Keep learning and building!
CONCLUSION
Binumon Joseph, Assistant Professor 8
Building Blocks of a Web Application
• User Interface - how users will consume and interact with your application.
• Routing - how users navigate between different parts of your application.
• Data Fetching - where your data lives and how to get it.
• Rendering - when and where you render static or dynamic content.
• Integrations - what third-party services you use (CMS, auth, payments, etc) and how
you connect to them.
• Infrastructure - where you deploy, store, and run your application code (Serverless,
CDN, Edge, etc).
• Performance - how to optimize your application for end-users.
• Scalability - how your application adapts as your team, data, and traffic grow.
• Developer Experience - your team’s experience building and maintaining your
application. 9
Binumon Joseph, Assistant Professor
React ?
Interactive User Interface
• JavaScript library for building
interactive user interfaces.
• User interfaces, - Elements that
users see and interact with on-
screen.
• Library - React provides helpful
functions to build UI, but leaves it up
to the developer where to use those
functions in their application.
10
Binumon Joseph, Assistant
Professor
Next.js?
• React framework that gives you building blocks to create web
applications.
• Framework - Next.js handles the tooling and configuration needed
for React, and provides additional structure, features, and
optimizations for your application.
11
Binumon Joseph, Assistant Professor
From JavaScript to React
12
Binumon Joseph, Assistant Professor
Rendering User Interfaces
13
Binumon Joseph, Assistant Professor
DOM vs UI
14
Binumon Joseph, Assistant Professor
UI update with
JavaScript
• Create new file index.html
<html>
<body>
<div id="app"></div>
<script type="text/javascript">
// Select the div element with 'app' id
const app = document.getElementById('app');
// Create a new H1 element
const header = document.createElement('h1');
// Create a new text node for the H1 element
const headerContent = document.createTextNode(
'Develop. Preview. Ship.',
);
// Append the text to the H1 element
header.appendChild(headerContent);
// Place the H1 element inside the div
app.appendChild(header);
</script>
</body>
</html>
15
Binumon Joseph, Assistant
Professor
Imperative vs Declarative Programming
• Imperative programming is like giving a chef step-by-step instructions
on how to make a pizza.
• Declarative programming is like ordering a pizza without being
concerned about the steps it takes to make the pizza.
• React is a Declarative Library
16
Binumon Joseph, Assistant Professor
Imperative vs Declarative Programming
• Imperative programming is like giving a chef step-by-step instructions
on how to make a pizza.
• Declarative programming is like ordering a pizza without being
concerned about the steps it takes to make the pizza.
• React is a Declarative Library
17
Binumon Joseph, Assistant Professor
Getting Started
with React
• To use React in your project,
you can load two React scripts
from an external website
called unpkg.com:
• react is the core React library.
• react-dom provides DOM-
specific methods that enable
you to use React with the DOM.
<!-- index.html -->
<html>
<body>
<div id="app"></div>
<script
src="https://unpkg.com/react@17/umd/react.dev
elopment.js"></script>
<script src="https://unpkg.com/react-
dom@17/umd/react-
dom.development.js"></script>
<script type="text/javascript">
const app = document.getElementById('app');
</script>
</body>
</html>
18
Binumon Joseph, Assistant Professor
Rendering React
• Instead of directly manipulating
the DOM with plain JavaScript,
you can use the
ReactDOM.render() method
from react-dom to tell React to
render our <h1> title inside our
#app element.
<!-- index.html -->
<html>
<body>
<div id="app"></div>
<script
src="https://unpkg.com/react@17/umd/react.dev
elopment.js"></script>
<script src="https://unpkg.com/react-
dom@17/umd/react-
dom.development.js"></script>
<script type="text/javascript">
const app = document.getElementById('app');
ReactDOM.render(<h1>Develop. Preview. Ship.
</h1>, app);
</script>
</body>
</html>
19
Binumon Joseph, Assistant Professor
JSX- JavaScript
Syntax Extension
• JSX is a syntax extension for JavaScript
that allows you to describe your UI in a
familiar HTML-like syntax.
• The nice thing about JSX is that apart from
following three JSX rules, you don’t need
to learn any new symbols or syntax outside
of HTML and JavaScript.
• Note that browsers don’t understand JSX
out of the box, so you’ll need a JavaScript
compiler, such as a Babel, to transform
your JSX code into regular JavaScript.
<html>
<body>
<div id="app"></div>
<script
src="https://unpkg.com/react@17/umd/react.developm
ent.js"></script>
<script src="https://unpkg.com/react-
dom@17/umd/react-dom.development.js"></script>
<!-- Babel Script -->
<script
src="https://unpkg.com/@babel/standalone/babel.min.j
s"></script>
<script type="text/jsx">
const app = document.getElementById('app');
ReactDOM.render(<h1>Develop. Preview. Ship. </h1>,
app);
</script>
</body>
</html>
20
Binumon Joseph, Assistant Professor
React Core Concepts
Components
User interfaces can
be broken down into
smaller building
blocks
Props State
21
Binumon Joseph, Assistant Professor
Component
22
Binumon Joseph, Assistant Professor
Component
• Creating components
• In React, components are functions. Inside
your script tag, write a function called
Header
<html>
<body>
<div id="app"></div>
<script
src="https://unpkg.com/react@17/umd/react.development.js">
</script>
<script src="https://unpkg.com/react-dom@17/umd/react-
dom.development.js"></script>
<script
src="https://unpkg.com/@babel/standalone/babel.min.js"></scr
ipt>
<script type="text/jsx">
const app = document.getElementById('app');
function Header() {
return <h1>Develop. Preview. Ship. </h1>;
}
ReactDOM.render(<Header />, app);
</script>
</body>
</html>
23
Binumon Joseph, Assistant Professor
Nesting
Components
• Applications usually include more
content than a single component. You
can nest React components inside
each other like you would regular
HTML elements.
<script type="text/jsx">
const app = document.getElementById('app');
function Header() {
return <h1>Develop. Preview. Ship. </h1>;
}
function HomePage() {
return ( <div> <Header /> </div> );
}
ReactDOM.render(<HomePage />, app);
</script>
24
Binumon Joseph, Assistant Professor
Component Trees
25
Binumon Joseph, Assistant Professor
Displaying Data with Props
• Regular HTML elements have attributes that you can use to pass
pieces of information that change the behavior of those elements.
For example, changing the src attribute of an <img> element
changes the image that is shown. Changing the href attribute of an
<a> tag changes the destination of the link.
• In the same way, you can pass pieces of information as properties
to React components. These are called props.
26
Binumon Joseph, Assistant Professor
Using props
• In your HomePage component, you
can pass a custom title prop to the
Header component, just like you’d
pass HTML attributes
<script type="text/jsx">
const app = document.getElementById('app');
function Header(props) {
return <h1>{props.title}</h1>;
}
function HomePage() {
return ( <div> <Header title="React 💙" />
<Header title="A new title" /> </div> );
}
ReactDOM.render(<HomePage />, app);
</script>
27
Binumon Joseph, Assistant Professor
Iterating through
lists
• It’s common to have data that you
need to show as a list. You can use
array methods to manipulate your data
and generate UI elements that are
identical in style but hold different
pieces of information.
function HomePage() {
const names = ['Ada Lovelace', 'Grace Hopper',
'Margaret Hamilton’];
return (
<div>
<Header title="Develop. Preview. Ship. " />
<ul>
{names.map((name) => (
<li key={name}>{name}</li>
))}
</ul>
</div>
);
}
28
Binumon Joseph, Assistant Professor
Adding Interactivity with State
• Listening to Events
• Handling Events
• State and Hooks
29
Binumon Joseph, Assistant Professor
State
• Listening to Events
• Handling Events
• State and Hooks
function HomePage() {
const [likes, setLikes] = React.useState(0);
function handleClick() {
setLikes(likes + 1);
}
return ( <div> {/* ... */}
<button onClick={handleClick}>Likes
({likes})</button>
</div> );
}
30
Binumon Joseph, Assistant Professor
From React to Next.js
31
Binumon Joseph, Assistant Professor
Starting with Next.js
• Install Node.js
• create a new file called package.json with an empty object {}
• In your terminal, run npm install react react-dom next
• Remove
• The react and react-dom scripts since you’ve installed them with NPM.
• The <html> and <body> tags because Next.js will create these for you.
• The code that interacts with app element and ReactDom.render() method.
• The Babel script because Next.js has a compiler that transforms JSX into valid
JavaScript browsers can understand.
• The <script type="text/jsx"> tag.
• The React. part of the React.useState(0) function
32
Binumon Joseph, Assistant Professor
// index.html
import { useState } from 'react’;
function Header({ title }) {
return <h1>{title ? title : 'Default
title'}</h1>;
}
function HomePage() {
const names = ['Ada Lovelace', 'Grace
Hopper', 'Margaret Hamilton’];
const [likes, setLikes] = useState(0);
function handleClick() {
setLikes(likes + 1);
}
return ( <div> <Header title="Develop.
Preview. Ship. " />
<ul>
{names.map((name) => (
<li key={name}>{name}</li>
))}
</ul>
<button onClick={handleClick}>Like
({likes})</button> </div>
);
}
33
Binumon Joseph, Assistant Professor
Changing Environment
1. Move the index.js file to a new folder called pages (more on this
later).
2. Add default export to your main React component to help Next.js
distinguish which component to render as the main component of
this page.
export default function HomePage() {
Add a script to your package.json file to run the Next.js development
server while you develop.
// package.json { "scripts": { "dev": "next dev" },
// "dependencies": { // "next": "^11.1.0", // "react": "^17.0.2", // "react-
dom": "^17.0.2" // } }
34
Binumon Joseph, Assistant Professor
Running the development server
import { useState } from 'react’;
function Header({ title }) {
return <h1>{title ? title : 'Default title'}</h1>;
}
export default function HomePage() {
const names = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton’];
const [likes, setLikes] = useState(0);
function handleClick() {
setLikes(likes + 1);
}
return ( <div> <Header title="Develop. Preview. Ship. " />
<ul>
{names.map((name) => (
<li key={name}>{name}</li>
))}
</ul>
<button onClick={handleClick}>Like ({likes})</button>
</div> );
}
npm run dev
35
Binumon Joseph, Assistant Professor
Create a Next.js App
npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter"
36
Binumon Joseph, Assistant Professor
Link Component
• On your pages/index.js
• To include link
<Link href="/posts/first-post">this page!</Link>
import Link from 'next/link';
37
Binumon Joseph, Assistant Professor
Assets, Metadata, and CSS
• Image Component and Image Optimization
import Image from 'next/image’;
return(
<Image src="/images/profile.jpg" // Route of the image file
height={144} // Desired size with correct aspect ratio
width={144} // Desired size with correct aspect ratio
alt="Your Name" />
);
38
Binumon Joseph, Assistant Professor
Adding Head
39
import Head from 'next/head';
export default function FirstPost() {
return ( <>
<Head> <title>First Post</title> </Head>
<h1>First Post</h1>
<h2> <Link href="/">← Back to home</Link> </h2> </>
);
}
Binumon Joseph, Assistant Professor
Adding CSS
• Create a file called components/layout.module.css with the
following content:
.container {
max-width: 36rem;
padding: 0 1rem;
margin: 3rem auto 6rem;
}
40
Binumon Joseph, Assistant Professor
Adding CSS
• Create a top-level directory called components.
• Inside components, create a file called layout.js with the following
content:
import styles from './layout.module.css’;
export default function Layout({ children }) {
return <div className={styles.container}>{children}</div>;
}
41
Binumon Joseph, Assistant Professor
Adding CSS
import Head from 'next/head’;
import Link from 'next/link’;
import Layout from '../../components/layout’;
export default function FirstPost() {
return ( <Layout>
<Head> <title>First Post</title> </Head>
<h1>First Post</h1>
<h2> <Link href="/">← Back to home</Link> </h2>
</Layout>
);
}
42
Binumon Joseph, Assistant Professor
THANKS
Do you have any questions?
binumonjosephk@amaljyothi.ac.in
+
919539 373 1
71
Binumon Joseph, Assistant Professor 43

More Related Content

What's hot

React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
Sunil Yadav
 
React web development
React web developmentReact web development
React web development
Rully Ramanda
 
reactJS
reactJSreactJS
reactJS
Syam Santhosh
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Intro to React
Intro to ReactIntro to React
Intro to React
Justin Reock
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
Alessandro Valenti
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React js
React jsReact js
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
 
Learn react-js
Learn react-jsLearn react-js
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
 
Universal React apps in Next.js
Universal React apps in Next.jsUniversal React apps in Next.js
Universal React apps in Next.js
🐕 Łukasz Ostrowski
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Knoldus Inc.
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
DivyanshGupta922023
 
Intro to react native
Intro to react nativeIntro to react native
Intro to react native
ModusJesus
 
React hooks
React hooksReact hooks
React hooks
Ramy ElBasyouni
 
ReactJs
ReactJsReactJs

What's hot (20)

React Js Simplified
React Js SimplifiedReact Js Simplified
React Js Simplified
 
React web development
React web developmentReact web development
React web development
 
reactJS
reactJSreactJS
reactJS
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
React js
React jsReact js
React js
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Reactjs
Reactjs Reactjs
Reactjs
 
Universal React apps in Next.js
Universal React apps in Next.jsUniversal React apps in Next.js
Universal React apps in Next.js
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
Intro to react native
Intro to react nativeIntro to react native
Intro to react native
 
React hooks
React hooksReact hooks
React hooks
 
ReactJs
ReactJsReactJs
ReactJs
 

Similar to NEXT.JS

How create react app help in creating a new react applications
How create react app help in creating a new react applications How create react app help in creating a new react applications
How create react app help in creating a new react applications
Concetto Labs
 
Web summit.pptx
Web summit.pptxWeb summit.pptx
Web summit.pptx
171SagnikRoy
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
Hamid Ghorbani
 
What is Server-side Rendering? How to Render Your React App on the Server-sid...
What is Server-side Rendering? How to Render Your React App on the Server-sid...What is Server-side Rendering? How to Render Your React App on the Server-sid...
What is Server-side Rendering? How to Render Your React App on the Server-sid...
Shelly Megan
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
IRJET Journal
 
COMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxCOMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docx
write31
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Why do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdfWhy do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdf
nearlearn
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
Denis Izmaylov
 
Next JS vs React.pptx
Next JS vs React.pptxNext JS vs React.pptx
Next JS vs React.pptx
Albiorix Technology
 
The Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSThe Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJS
WeblineIndia
 
Boost Startup Success: Hire Skilled ReactJS Developers Today
Boost Startup Success: Hire Skilled ReactJS Developers TodayBoost Startup Success: Hire Skilled ReactJS Developers Today
Boost Startup Success: Hire Skilled ReactJS Developers Today
BOSC Tech Labs
 
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web ApplicationReact Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
adityakumar2080
 
Progressive Web Apps and React
Progressive Web Apps and ReactProgressive Web Apps and React
Progressive Web Apps and React
Mike Melusky
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 
React Native App Development.
React Native App Development.React Native App Development.
React Native App Development.
Techugo
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
Eamonn Boyle
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
Atlogys Technical Consulting
 
Vered Flis: Because performance matters! Architecture Next 20
Vered Flis: Because performance matters! Architecture Next 20Vered Flis: Because performance matters! Architecture Next 20
Vered Flis: Because performance matters! Architecture Next 20
CodeValue
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Bethmi Gunasekara
 

Similar to NEXT.JS (20)

How create react app help in creating a new react applications
How create react app help in creating a new react applications How create react app help in creating a new react applications
How create react app help in creating a new react applications
 
Web summit.pptx
Web summit.pptxWeb summit.pptx
Web summit.pptx
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
 
What is Server-side Rendering? How to Render Your React App on the Server-sid...
What is Server-side Rendering? How to Render Your React App on the Server-sid...What is Server-side Rendering? How to Render Your React App on the Server-sid...
What is Server-side Rendering? How to Render Your React App on the Server-sid...
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 
COMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxCOMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docx
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
 
Why do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdfWhy do we use react JS on the website_.pdf
Why do we use react JS on the website_.pdf
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
 
Next JS vs React.pptx
Next JS vs React.pptxNext JS vs React.pptx
Next JS vs React.pptx
 
The Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSThe Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJS
 
Boost Startup Success: Hire Skilled ReactJS Developers Today
Boost Startup Success: Hire Skilled ReactJS Developers TodayBoost Startup Success: Hire Skilled ReactJS Developers Today
Boost Startup Success: Hire Skilled ReactJS Developers Today
 
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web ApplicationReact Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
 
Progressive Web Apps and React
Progressive Web Apps and ReactProgressive Web Apps and React
Progressive Web Apps and React
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
 
React Native App Development.
React Native App Development.React Native App Development.
React Native App Development.
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
 
Vered Flis: Because performance matters! Architecture Next 20
Vered Flis: Because performance matters! Architecture Next 20Vered Flis: Because performance matters! Architecture Next 20
Vered Flis: Because performance matters! Architecture Next 20
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 

More from Binumon Joseph

thunderbolt interface
thunderbolt interfacethunderbolt interface
thunderbolt interface
Binumon Joseph
 
Thunderbolt interface
Thunderbolt interfaceThunderbolt interface
Thunderbolt interface
Binumon Joseph
 
sixth sense technology
sixth sense technologysixth sense technology
sixth sense technology
Binumon Joseph
 
globel wireless e votingSlides
globel wireless e votingSlidesglobel wireless e votingSlides
globel wireless e votingSlides
Binumon Joseph
 
Multi touch
Multi touchMulti touch
Multi touch
Binumon Joseph
 
Speed detection using camera
Speed detection using cameraSpeed detection using camera
Speed detection using camera
Binumon Joseph
 

More from Binumon Joseph (6)

thunderbolt interface
thunderbolt interfacethunderbolt interface
thunderbolt interface
 
Thunderbolt interface
Thunderbolt interfaceThunderbolt interface
Thunderbolt interface
 
sixth sense technology
sixth sense technologysixth sense technology
sixth sense technology
 
globel wireless e votingSlides
globel wireless e votingSlidesglobel wireless e votingSlides
globel wireless e votingSlides
 
Multi touch
Multi touchMulti touch
Multi touch
 
Speed detection using camera
Speed detection using cameraSpeed detection using camera
Speed detection using camera
 

Recently uploaded

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

NEXT.JS

  • 1. NEXT.JS Next.js is a flexible React framework that gives you building blocks to create fast web applications. 1 Binumon Joseph, Assistant Professor
  • 2. MASTERI NG SERVER-SI DE RENDERI NG WI TH NEXT.JS: A COMPREHENSIVE TUTORIAL Binumon Joseph, Assistant Professor 2
  • 3. INTRODUCTION Server-Side Rendering (SSR)is a technique that allows your web application to pre-render HTML on a server,providing faster load times and a better user experience.In this tutorial, we'll cover Next.js,a framework for building server-rendered React applications. Binumon Joseph, Assistant Professor 3
  • 4. WhyUseSSR? SSR can improve SEO,performance, and user experience. It allows search engines to better crawl your site, reduces the time to first paint,and provides users with a fully rendered page on the initial load. Next.js simplifies the process of building SSR applications. Binumon Joseph, Assistant Professor 4
  • 5. GETTINGSTARTEDWITHNEXT.JS To get started with Next.js,you'll need to install it and create a new project.Next.js provides several built-in features,such as dynamic imports,automatic code splitting,and server-side rendering.You can also easily add custom routes and API endpoints. Binumon Joseph, Assistant Professor 5
  • 6. T o build pages with Next.js,you'll create a pages directory and add React components for each page. Next.js uses getI nitialProps to fetch data and render the page on the server.You can also use dynamic routing and static site generation to optimize performance. BUILDINGPAGESWITHNEXT.JS Binumon Joseph, Assistant Professor 6
  • 7. Deploying Your Next.js App Next.js makes it easy to deploy your app to Vercel,a cloud platform for static and serverless sites.Vercel provides automatic SSL,custom domains,and global CDN.You can also deploy to other platforms such as Heroku or AWS. Binumon Joseph, Assistant Professor 7 DeployingYourNext.jsApp
  • 8. Next.js provides a powerful framework for building server-rendered React applications. By using SSR, you can improve SEO, performance, and user experience. With Next.js, you can easily create dynamic routes, API endpoints, and deploy your app to the cloud. Keep learning and building! CONCLUSION Binumon Joseph, Assistant Professor 8
  • 9. Building Blocks of a Web Application • User Interface - how users will consume and interact with your application. • Routing - how users navigate between different parts of your application. • Data Fetching - where your data lives and how to get it. • Rendering - when and where you render static or dynamic content. • Integrations - what third-party services you use (CMS, auth, payments, etc) and how you connect to them. • Infrastructure - where you deploy, store, and run your application code (Serverless, CDN, Edge, etc). • Performance - how to optimize your application for end-users. • Scalability - how your application adapts as your team, data, and traffic grow. • Developer Experience - your team’s experience building and maintaining your application. 9 Binumon Joseph, Assistant Professor
  • 10. React ? Interactive User Interface • JavaScript library for building interactive user interfaces. • User interfaces, - Elements that users see and interact with on- screen. • Library - React provides helpful functions to build UI, but leaves it up to the developer where to use those functions in their application. 10 Binumon Joseph, Assistant Professor
  • 11. Next.js? • React framework that gives you building blocks to create web applications. • Framework - Next.js handles the tooling and configuration needed for React, and provides additional structure, features, and optimizations for your application. 11 Binumon Joseph, Assistant Professor
  • 12. From JavaScript to React 12 Binumon Joseph, Assistant Professor
  • 13. Rendering User Interfaces 13 Binumon Joseph, Assistant Professor
  • 14. DOM vs UI 14 Binumon Joseph, Assistant Professor
  • 15. UI update with JavaScript • Create new file index.html <html> <body> <div id="app"></div> <script type="text/javascript"> // Select the div element with 'app' id const app = document.getElementById('app'); // Create a new H1 element const header = document.createElement('h1'); // Create a new text node for the H1 element const headerContent = document.createTextNode( 'Develop. Preview. Ship.', ); // Append the text to the H1 element header.appendChild(headerContent); // Place the H1 element inside the div app.appendChild(header); </script> </body> </html> 15 Binumon Joseph, Assistant Professor
  • 16. Imperative vs Declarative Programming • Imperative programming is like giving a chef step-by-step instructions on how to make a pizza. • Declarative programming is like ordering a pizza without being concerned about the steps it takes to make the pizza. • React is a Declarative Library 16 Binumon Joseph, Assistant Professor
  • 17. Imperative vs Declarative Programming • Imperative programming is like giving a chef step-by-step instructions on how to make a pizza. • Declarative programming is like ordering a pizza without being concerned about the steps it takes to make the pizza. • React is a Declarative Library 17 Binumon Joseph, Assistant Professor
  • 18. Getting Started with React • To use React in your project, you can load two React scripts from an external website called unpkg.com: • react is the core React library. • react-dom provides DOM- specific methods that enable you to use React with the DOM. <!-- index.html --> <html> <body> <div id="app"></div> <script src="https://unpkg.com/react@17/umd/react.dev elopment.js"></script> <script src="https://unpkg.com/react- dom@17/umd/react- dom.development.js"></script> <script type="text/javascript"> const app = document.getElementById('app'); </script> </body> </html> 18 Binumon Joseph, Assistant Professor
  • 19. Rendering React • Instead of directly manipulating the DOM with plain JavaScript, you can use the ReactDOM.render() method from react-dom to tell React to render our <h1> title inside our #app element. <!-- index.html --> <html> <body> <div id="app"></div> <script src="https://unpkg.com/react@17/umd/react.dev elopment.js"></script> <script src="https://unpkg.com/react- dom@17/umd/react- dom.development.js"></script> <script type="text/javascript"> const app = document.getElementById('app'); ReactDOM.render(<h1>Develop. Preview. Ship. </h1>, app); </script> </body> </html> 19 Binumon Joseph, Assistant Professor
  • 20. JSX- JavaScript Syntax Extension • JSX is a syntax extension for JavaScript that allows you to describe your UI in a familiar HTML-like syntax. • The nice thing about JSX is that apart from following three JSX rules, you don’t need to learn any new symbols or syntax outside of HTML and JavaScript. • Note that browsers don’t understand JSX out of the box, so you’ll need a JavaScript compiler, such as a Babel, to transform your JSX code into regular JavaScript. <html> <body> <div id="app"></div> <script src="https://unpkg.com/react@17/umd/react.developm ent.js"></script> <script src="https://unpkg.com/react- dom@17/umd/react-dom.development.js"></script> <!-- Babel Script --> <script src="https://unpkg.com/@babel/standalone/babel.min.j s"></script> <script type="text/jsx"> const app = document.getElementById('app'); ReactDOM.render(<h1>Develop. Preview. Ship. </h1>, app); </script> </body> </html> 20 Binumon Joseph, Assistant Professor
  • 21. React Core Concepts Components User interfaces can be broken down into smaller building blocks Props State 21 Binumon Joseph, Assistant Professor
  • 23. Component • Creating components • In React, components are functions. Inside your script tag, write a function called Header <html> <body> <div id="app"></div> <script src="https://unpkg.com/react@17/umd/react.development.js"> </script> <script src="https://unpkg.com/react-dom@17/umd/react- dom.development.js"></script> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></scr ipt> <script type="text/jsx"> const app = document.getElementById('app'); function Header() { return <h1>Develop. Preview. Ship. </h1>; } ReactDOM.render(<Header />, app); </script> </body> </html> 23 Binumon Joseph, Assistant Professor
  • 24. Nesting Components • Applications usually include more content than a single component. You can nest React components inside each other like you would regular HTML elements. <script type="text/jsx"> const app = document.getElementById('app'); function Header() { return <h1>Develop. Preview. Ship. </h1>; } function HomePage() { return ( <div> <Header /> </div> ); } ReactDOM.render(<HomePage />, app); </script> 24 Binumon Joseph, Assistant Professor
  • 25. Component Trees 25 Binumon Joseph, Assistant Professor
  • 26. Displaying Data with Props • Regular HTML elements have attributes that you can use to pass pieces of information that change the behavior of those elements. For example, changing the src attribute of an <img> element changes the image that is shown. Changing the href attribute of an <a> tag changes the destination of the link. • In the same way, you can pass pieces of information as properties to React components. These are called props. 26 Binumon Joseph, Assistant Professor
  • 27. Using props • In your HomePage component, you can pass a custom title prop to the Header component, just like you’d pass HTML attributes <script type="text/jsx"> const app = document.getElementById('app'); function Header(props) { return <h1>{props.title}</h1>; } function HomePage() { return ( <div> <Header title="React 💙" /> <Header title="A new title" /> </div> ); } ReactDOM.render(<HomePage />, app); </script> 27 Binumon Joseph, Assistant Professor
  • 28. Iterating through lists • It’s common to have data that you need to show as a list. You can use array methods to manipulate your data and generate UI elements that are identical in style but hold different pieces of information. function HomePage() { const names = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton’]; return ( <div> <Header title="Develop. Preview. Ship. " /> <ul> {names.map((name) => ( <li key={name}>{name}</li> ))} </ul> </div> ); } 28 Binumon Joseph, Assistant Professor
  • 29. Adding Interactivity with State • Listening to Events • Handling Events • State and Hooks 29 Binumon Joseph, Assistant Professor
  • 30. State • Listening to Events • Handling Events • State and Hooks function HomePage() { const [likes, setLikes] = React.useState(0); function handleClick() { setLikes(likes + 1); } return ( <div> {/* ... */} <button onClick={handleClick}>Likes ({likes})</button> </div> ); } 30 Binumon Joseph, Assistant Professor
  • 31. From React to Next.js 31 Binumon Joseph, Assistant Professor
  • 32. Starting with Next.js • Install Node.js • create a new file called package.json with an empty object {} • In your terminal, run npm install react react-dom next • Remove • The react and react-dom scripts since you’ve installed them with NPM. • The <html> and <body> tags because Next.js will create these for you. • The code that interacts with app element and ReactDom.render() method. • The Babel script because Next.js has a compiler that transforms JSX into valid JavaScript browsers can understand. • The <script type="text/jsx"> tag. • The React. part of the React.useState(0) function 32 Binumon Joseph, Assistant Professor
  • 33. // index.html import { useState } from 'react’; function Header({ title }) { return <h1>{title ? title : 'Default title'}</h1>; } function HomePage() { const names = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton’]; const [likes, setLikes] = useState(0); function handleClick() { setLikes(likes + 1); } return ( <div> <Header title="Develop. Preview. Ship. " /> <ul> {names.map((name) => ( <li key={name}>{name}</li> ))} </ul> <button onClick={handleClick}>Like ({likes})</button> </div> ); } 33 Binumon Joseph, Assistant Professor
  • 34. Changing Environment 1. Move the index.js file to a new folder called pages (more on this later). 2. Add default export to your main React component to help Next.js distinguish which component to render as the main component of this page. export default function HomePage() { Add a script to your package.json file to run the Next.js development server while you develop. // package.json { "scripts": { "dev": "next dev" }, // "dependencies": { // "next": "^11.1.0", // "react": "^17.0.2", // "react- dom": "^17.0.2" // } } 34 Binumon Joseph, Assistant Professor
  • 35. Running the development server import { useState } from 'react’; function Header({ title }) { return <h1>{title ? title : 'Default title'}</h1>; } export default function HomePage() { const names = ['Ada Lovelace', 'Grace Hopper', 'Margaret Hamilton’]; const [likes, setLikes] = useState(0); function handleClick() { setLikes(likes + 1); } return ( <div> <Header title="Develop. Preview. Ship. " /> <ul> {names.map((name) => ( <li key={name}>{name}</li> ))} </ul> <button onClick={handleClick}>Like ({likes})</button> </div> ); } npm run dev 35 Binumon Joseph, Assistant Professor
  • 36. Create a Next.js App npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter" 36 Binumon Joseph, Assistant Professor
  • 37. Link Component • On your pages/index.js • To include link <Link href="/posts/first-post">this page!</Link> import Link from 'next/link'; 37 Binumon Joseph, Assistant Professor
  • 38. Assets, Metadata, and CSS • Image Component and Image Optimization import Image from 'next/image’; return( <Image src="/images/profile.jpg" // Route of the image file height={144} // Desired size with correct aspect ratio width={144} // Desired size with correct aspect ratio alt="Your Name" /> ); 38 Binumon Joseph, Assistant Professor
  • 39. Adding Head 39 import Head from 'next/head'; export default function FirstPost() { return ( <> <Head> <title>First Post</title> </Head> <h1>First Post</h1> <h2> <Link href="/">← Back to home</Link> </h2> </> ); } Binumon Joseph, Assistant Professor
  • 40. Adding CSS • Create a file called components/layout.module.css with the following content: .container { max-width: 36rem; padding: 0 1rem; margin: 3rem auto 6rem; } 40 Binumon Joseph, Assistant Professor
  • 41. Adding CSS • Create a top-level directory called components. • Inside components, create a file called layout.js with the following content: import styles from './layout.module.css’; export default function Layout({ children }) { return <div className={styles.container}>{children}</div>; } 41 Binumon Joseph, Assistant Professor
  • 42. Adding CSS import Head from 'next/head’; import Link from 'next/link’; import Layout from '../../components/layout’; export default function FirstPost() { return ( <Layout> <Head> <title>First Post</title> </Head> <h1>First Post</h1> <h2> <Link href="/">← Back to home</Link> </h2> </Layout> ); } 42 Binumon Joseph, Assistant Professor
  • 43. THANKS Do you have any questions? binumonjosephk@amaljyothi.ac.in + 919539 373 1 71 Binumon Joseph, Assistant Professor 43