React Framework
Next.js is an open-source React framework that enables functionality such as server-side rendering, static site generation, and serverless functions. Created by Vercel (formerly Zeit), Next.js provides a production-ready framework with all the features needed for building modern web applications.
Next.js simplifies the development process by providing built-in features like routing, image optimization, and API routes while maintaining the React component model that developers are familiar with.
// pages/index.js import Head from 'next/head' export default function HomePage() { return ( <div> <Head> <title>My Next.js Site</title> <meta name="description" content="Built with Next.js" /> </Head> <main> <h1>Welcome to Next.js!</h1> <p>Get started by editing this page</p> </main> </div> ) }
// pages/posts/[id].js export default function Post({ post }) { return ( <div> <h1>{post.title}</h1> <p>{post.content}</p> </div> ) } // This function runs on every request export async function getServerSideProps(context) { const { id } = context.params const res = await fetch(`https://api.example.com/posts/${id}`) const post = await res.json() return { props: { post }, // Will be passed to the page component as props } }
// pages/api/hello.js export default function handler(req, res) { const { method } = req switch (method) { case 'GET': res.status(200).json({ message: 'Hello from Next.js!' }) break case 'POST': // Process POST request res.status(200).json({ message: 'Data received' }) break default: res.setHeader('Allow', ['GET', 'POST']) res.status(405).end(`Method ${method} Not Allowed`) } }
Next.js is primarily used for:
Major milestones in Next.js's development:
Next.js continues to evolve with a focus on developer experience and performance enhancements.
Here are some excellent resources for learning Next.js:
Technologies often used with Next.js or alternative options: