On To The ‘Next’ Journey!

  1. What is Next.js?
  2. Server-Side-rendering(SSR)
  3. Static and Dynamic Rendering
  4. Client-Side-rendering(CSR)
  5. Use Client
  6. App Router
  7. Tips and Tricks

> What is Next.js?

Next.js is a popular React framework(tools, libraries) that allows fast, high-performing, scalable, and search-engine-friendly web apps. It’s mainly used for building web pages and is designed to enable server-side rendering and static site generation, providing a range of features and optimizations outside the box.

Next.js offers several great benefits, with the biggest being its ease of use and how quickly it handles data fetching. Built on top of React, Next.js makes your life easier with simple file-based routing and automatic code splitting. You can create routes just by adding files to the pages directory, no complicated setup is needed. It also has hot-reloading, which lets you see your changes instantly without refreshing the page, saving you loads of time.

Next.js also makes data fetching fast with server-side rendering (SSR) and static site generation (SSG). With SSR, it fetches data on the server, loads the page with the data, and then sends it to the client. On the other hand, SSG creates HTML at build time, so your content is ready and waiting for users immediately.

These features make your website load faster and run smoother, giving users a better experience. You can even style Next.js using tailwind.css, which makes the designing process simple and concise. There is no need to label each div in your return statements, just add your styling directly on the tag!

SSR

Let’s Talk more about Next.js key uses, like Server-side-rendering (SSR): Server-side rendering? Yes! That’s a thing. It allows developers to create hybrid applications where parts of the application can be on the server and parts can be on the client.

Server-side rendering is similar to client-side-rendering(CSR, when the front end has to wait for instructions from the server to render details), except SSR renders web pages on the server and sends them to the client’s browser. A few key benefits of SSR include:

  • fewer resources since the server handles most of the rendering
  • smaller bundles by using Code splitting (divides the JavaScript code into multiple smaller bundles)
  • improving load time and performance
  • Search Engine Optimization (SEO).

SSR

STATIC & DYNAMIC RENDERING

SSR also involves two kinds of rendering, static and dynamic. With static rendering, Next.js usually renders data from the database as a static page which means it renders data while building out your code for your project. By default, Next.js will cache the fetched data, either from an API or database, by using the fetch function, but Next.js also allows you to disable cache which will also change how the page renders. Instead, it will switch to dynamic rendering, rendering the page at the requested time.

CSR

Client-side rendering is still the same old process where the client waits for instructions from the server to render the data on the client’s browser.

You’re probably wondering why not just use one or the other.
Although SSR is fantastic, there are a few important factors that server-side components cannot manage, for example, state or effect hooks, browser features like “onClick” or n react”onChange”, or other aspects of the browser APIs. This is why we often use a mixture of client and server components, we only use client components when needed.

Use client

Inside of client-side components, we want to make sure that we state the ‘use client’ import at the top of the file ensuring that any client-side specific behavior is correctly handled. This provides clarity and consistency especially when using Event listeners (like onClick,onChange, etc.) which should only be attached in the client environment. Also, remember that the ‘use client’ import doesn’t mean that every child wrapped in a component will use the client side, but if the component is dynamic, it’s best to still wrap the children.

visual of using 'use client'

APP ROUTER

Following. These are the key differences between JS and React/javascript, React uses JSX, a syntax extension that allows HTML-like code to be written within JavaScript and the way Routing works is different! Provided by the App Router(a system that handles routing by mapping URL paths to corresponding components or pages, making navigation within the application seamless and efficient), it uses the file system to provide routing for a Next.js application. In other words, you don’t need to create endpoints like you might in Express, or create a folder that holds all your routing, routes are
automatically generated based on your file system, usually stored in the layout.tsx page!

routing system

Pretty cool, right?

TIPS AND TRICKS

Utilize these resources to get your feet wet and explore as you go about your journey in learning next.js, I guarantee you will be able to create something you never even thought you could! Using next.js over JavaScript has been such a lifesaver! Remember, It’s designed to make your development process smoother and your applications faster and more efficient. Don’t feel intimidated by the process of learning; with the right mindset and these resources, you’ll be amazed at what you can achieve. Check out these amazing guides below to kickstart your journey and learn more about Next.js!


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top