The Next.js is React Based framework with server side rendering capability. It is very fast and SEO friendly. Using Next.js, you can create robust react based application quite easily and test them.
The Next.js is React Based framework with server side rendering capability. It is very fast
and SEO friendly.
Using Next.js, you can create robust react based application quite easily and test them.
Following are the key features of Next.js.
Hot Code Reload : Next.js server detects modified files and reloads them automatically.
Automatic Routing : No need to configure any url for routing. files are to be placed in
pages folder. All urls will be mapped to file system. Customization can be done.
Component specific styles : styled-jsx provides support for global as well as component
specific styles.
Server side rendering : react components are prerendered on server hence loads faster on
client.
Node Ecosystem : Next.js being react based gels well with Node ecosystem.
Automatic code split : Next.js renders pages with libraries they need. Next.js instead of
creating a single large javascript file, creates multiples resources. When a page is loaded,
only required javascript page is loaded with it.
Prefetch : Next.js provides Link component which is used to link multiple components
supports a prefetch property to prefetch page resources in background.
Dynamic Components : Next.js allows to import JavaScript modules and React Components
dynamically.
Export Static Site : Next.js allows to export full static site from your web application.
Built-in Typescript Support : Next.js is written in Typescripts and provides excellent
Typescript support.
npx create-next-app@latest
yarn create next-app
npm run start
yarn run dev
import Link from 'next/link'
<ul>
<li>
<Link href="/">Home</Link>
</li>
<li>
<Link href="/about">About Us</Link>
</li>
<li>
<Link href="/blog/hello-world">Blog Post</Link>
</li>
</ul>
<h1>
//heading content
</h1>
import StyleSheet from '@/app/styles/main.module.css'
const page = () => {
return (
<div>
<h1 className={StyleSheet.mainmy}>contactus</h1>
</div>
)
}
export default page
import { Roboto } from 'next/font/google'
const roboto = Roboto({
weight: '400',
subsets: ['latin'],
display: 'swap',
})
export default function RootLayout({ children }) {
return (
<html lang="en" className={roboto.className}>
<body>{children}</body>
</html>
)
}
<Link href={`/movie/${id}`}>
import mongoose from "mongoose";
const MONGODB_URL = process.env.MONGODB_URL;
if (!MONGODB_URL) {throw new Error("Please define the MONGODB_URI environment variable inside .env.local" )}
let cached = global.mongoose;
if (!cached) {cached = global.mongoose = { con: null, promise: null }}
const dbConnect = async () => {
if (cached.conn) {return cached.conn; }
if (!cached.promise) {
const opts = { bufferCommands: false };
cached.promise = mongoose.connect(MONGODB_URL, opts).then((mongoose) => {return mongoose;});}
try {cached.conn = await cached.promise;} catch (e) {
cached.promise = null;
throw e;
}
return cached.conn;
};
export default dbConnect;