Book Image

Real-World Next.js

By : Michele Riva
Book Image

Real-World Next.js

By: Michele Riva

Overview of this book

Next.js is a scalable and high-performance React.js framework for modern web development and provides a large set of features, such as hybrid rendering, route prefetching, automatic image optimization, and internationalization, out of the box. If you are looking to create a blog, an e-commerce website, or a simple website, this book will show you how you can use the multipurpose Next.js framework to create an impressive user experience. Starting with the basics of Next.js, the book demonstrates how the framework can help you reach your development goals. You'll realize how versatile Next.js is as you build real-world applications with step-by-step explanations. This Next.js book will guide you in choosing the right rendering methodology for your website, securing it, and deploying it to different providers, all while focusing on performance and developer happiness. By the end of the book, you'll be able to design, build, and deploy modern architectures using Next.js with any headless CMS or data source.
Table of Contents (19 chapters)
Part 1: Introduction to Next.js
Part 2: Hands-On Next.js
Part 3: Next.js by Example

Moving from React to Next.js

If you already have some experience with React, you'll find it incredibly easy to build your first Next.js website. Its philosophy is very close to React and provides a convention-over-configuration approach for most of its settings, so if you want to take advantage of a specific Next.js feature, you'll easily find the official way for doing it without any need for complex configurations. An example? In a single Next.js app, you can specify which pages shall be server-side rendered and which shall be statically generated at build time without the need to write any configuration files or anything like that. You just have to export a specific function from your page and let Next.js do its magic (we'll see that in Chapter 2, Exploring Different Rendering Strategies).

The most significant difference between React and Next.js is that while React is just a JavaScript library, Next.js is a framework for building rich and complete user experiences both on the client and server sides, adding tons of incredibly useful features. Every server-side rendered or statically generated page will run on Node.js, so you'll lose access to some browser-specific global objects, such as fetch, window, and document, as well as some HTML elements such as canvas. You will always need to keep that in mind when you're writing your Next.js pages, even if the framework provides its own way for dealing with components that must use such global variables and HTML elements, as we'll see in Chapter 2, Exploring Different Rendering Strategies.

On the other hand, there might be times when you want to use Node.js specific libraries or APIs, such as fs or child_process, and Next.js allows you to use them by running your server-side code on each request or at build time (depending on how you choose to render your pages) before sending the data to the client.

But even if you want to create a client-side rendered app, Next.js can be a great alternative to the well-known create-react-app. Next.js, in fact, can be used as a framework for writing progressive and offline-first web apps with ease, taking advantage of its incredible built-in components and optimizations. So let's get started with Next.js.