The Advantages of using Next.js + Strapi vs React + Strapi
Tags: nextjs, reactnative, strapi, cms
Published: 2021-11-29 15:40:35

There are hundreds of libraries and frameworks to choose from in the Jamstack world. As there are some benefits and drawbacks to selecting some over others. And in this article, we'll compare the benefits of using next.js and create-react-app (CRA) with strapi as a headless CMS.

## What is Strapi

Strapi is an open-source, self-hosting, and database agnostic headless API with a fully customizable CMS front-end. With strapi, it's never been easier to create a customizable and performance content API. 

It saves weeks of API development time and allows for easy long-term content management via a user-friendly administration panel, and guess what? It's completely free!!!

## What is Next.js

Next.js is a react framework for creating single-page Javascript applications (SPA). It supports static export, pre-rendering, and other useful features such as automated building size optimization, quicker developer compilation, and a preview mode. 

Next.js provides the finest developer experience with all of the capabilities you need for production, like hybrid static and server rendering, TypeScript support, smart bundling, route prefetching, and more.

## What is create-react-app?

Create React App (CRA) is an officially approved method for developing single-page React apps. It provides a contemporary build setup that requires minimal configuration. With CRA, It is not necessary to install or set up technologies such as Webpack or Babel. They are preset and hidden so that you may concentrate on the code.

## Why Should We Compare Next.js vs create-react-app and Strapi?

When choosing any software library or framework, developer experience is usually taken into account. When I talk about developer experience, I mean how developers complete a task. Developers tend to favor libraries or frameworks that are fun and easy to use. This is the main reason we have leading libraries and frameworks today.
 
In the React world, Next.js has become a popular framework for "getting to the point." As I know, React fans take Next.js and enjoy working with it in their projects. 
 
Next.js is built on top of React to make development easier. Next.js takes a little getting used to, but even developers new to the front-end world can quickly start. So, it comes out that there is a different experience building a project with Next.js and React.

The next title will go deeper into the details of comparing both next.js + strapi and CRA + strapi while discussing their performance, ease of use, what it is like to initially launch a project, learn these technologies, and their documentation.

## Using CRA and strapi

The process of starting a new react app with strapi as its back-end is fairly simple. To begin, run the following command to create a new react app:

```bash
    npx create-react-app project-name
```

The next step is to create a new strapi project, which we can do by running the following command:

```
    npx create-strapi-app project-name
    # OR
    yarn create strapi-app project-name
```

Running the command above will prompt questions about the type of installation, whether you want to use a template and other options, but you can answer them all according to your preferences.

Finally, an HTTP client is required to make requests to the strapi API. We can use Axios for tasks like this one:

```
    npm install axios
    # OR
    yarn add axios
```

**Using next.js and strapi**

The procedure for creating a new strapi application using next.js as its front-end is identical to the one we followed for React above, with the exception that you'll need to build a next.js app first, which you can accomplish by running:

```bash
    npx create-next-app project-name
```

## Comparing Next.js and strapi vs CRA and strapi:

This section will compare both based on the following criteria for us to have a thorough understanding:

- Speed and easiness of code
- Performance
- SEO optimization
- Data fetching
- Features

So let's get right into it.

**Speed and easiness of coding:**

Next.js was crafted with a ton of built-in functionality to make creating react apps easier and faster. 

For example, next.js comes with its file-system based routing, which means you won't have to install `react-router` or configure routes and import components for different routes; all you have to do is create a `pages` folder in your project root directory, and the routes will be generated automatically for all the `.js` files in this folder, which is ideal for a strapi application because you'll most likely be working with routable objects.

**Performance**

Compared to react, apps developed using Next.js are lightning-fast due to their static-site and server-side rendering features. Furthermore, server-side rendering is advantageous for strapi applications because it lets you load data before a component is mounted into view, which improves speed.

**SEO Optimization**

Strapi is undoubtedly one of the best headless CMS for SEO available, owing to its versatility and content clustering function. 

However, while deciding whether to use CRA or next.js for better SEO optimization, next.js comes out on top because React applications do not have support for server-side rendering and will serve a complete application from a single entry point. Search engines crawling this website will only be able to view material from that single initial page.

**Data Fetching**

To fetch asynchronous data in react, you'll need to go through an extra step of installing additional libraries, such as the `react-async` library. 

Although you can choose to fetch these types of data directly in the `useEffect()` hook, doing so has its limitations, as it will be more complex to handle asynchronous UI states. 

Next.js, on the other hand, next.js comes with its data fetching technique, with support for both static-site and server-side created apps. 

This is advantageous for strapi since you will undoubtedly want the material from your API to be loaded as quickly and efficiently as possible.

**Additional Features**

Some other advantages Next.js has over CRA include:

1. Automatic compilation and bundling with no configuration. From the beginning, it was designed to be production-ready.
2. Hybrid: SSG and SSR: In a single project, pre-render pages at build time (SSG) or request time (SSR).
3. Incremental Static Generation: After the build time, incrementally add and update statically pre-rendered pages.
4. TypeScript Compilation and Configuration: TypeScript is automatically configured and compiled.
5. Automatic TypeScript configuration and compilation with Fast Refresh.


## **Advantages Of Using Next.js and Strapi**

Some other advantages of using next.js with strapi includes:

- Enhanced Security: You don't need a server-side language with Strapi, and your attack surface area is reduced.
- Infinite scalability: is a feature that allows you to scale your system to any size you want. You can use Strapi and Next.js indefinitely and scale as your business grows.
- Next.js is opinionated: Next.js is a framework with strong convictions. This means that the design paradigm of "convention over configuration" is prioritized. It compels designers to think and code in a specific manner.
- Better image optimization: It offers image optimization.
- It is the best option for server-side rendering and generating static websites.

## **Advantages of using CRA and Strapi**

While next.js has been favored in working with strapi throughout this article, you'll most likely need to know how create-react-app works before learning how to work with next.js.
In contrast, some of the benefits of using CRA with strapi include:

- Easy to get started
- Furthermore, unlike next.js, you won't need to learn any new concepts when working with CRA. Because next.js requires you to learn new concepts to do certain things.

## **Conclusion**

In conclusion, Next.js tends to have more features and tools for working behind the scenes like, when SEO matters or when building a landing page or building websites, Next.js is very fast. In contrast, creating a React app has more resources to work on your web or mobile application's front-end or build a gated application.