DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Alesia Sirotka for Flatlogic

Posted on • Originally published at flatlogic.com

Next.js vs React: Which One to Choose for Your App?

The burning question today is What’s better: React or Next.js? Let’s have a look closely at both, compare them and see the difference between library and framework. In the React world, Next.js is one of the most popular frameworks for β€œhitting the ground running.”

What is Next.js?

Next.js is an open-source JavaScript framework for developing fast, lightweight, and easy-to-use web applications and static websites (one-pages) using React. Next.js was created by Vercel in 2016. Next.js requires Node.js and can be initialized using npm. There are a lot of reasons why Next.js has such a strong reputation in the world of application development. They are known for being reliable as they offer image optimization, internationalization, zero-config, Next.js analytics, hybrid: SSR and SGG, fast refresh, API routes, TypeScript support, file-system routing, code-splitting and bundling, incremental static regeneration, and built-in CSS support, etc.

Next.js includes all the features needed to build an application. Moreover, the documentation is excellent and it is becoming very popular among developers for frontend development.Here are the most popular platforms and apps of Next.js: Twitch.tv, TikTok, Hulu, Binance, and many others that involve a massive number of users engaging with complex data influxes.

What is React?

React is an efficient, declarative and flexible JavaScript library for building interactive UI, inspired by xHP, the HTML component library for PHP. React was created by Facebook in 2011 and then open-sourced in 2013.React is used to create dynamic, mobile apps, one-pages, visualization tools, and dashboards. Here are some of the most popular platforms and apps created with React: Facebook, Netflix, Atlassian, Airbnb, Dropbox, Reddit, etc.

Next.js vs React

Even in a sea of JavaScript frameworks and libraries, React and NextJS stand out. React is the most popular JavaScript library for frontend developers. NextJS, although smaller than React, has grown continuously over the years and is well on its way to becoming the most-used JavaScript framework. So, let’s compare React and Next.js. React – is a JavaScript library for building UI. Next.js – is the React framework. NextJS is used on top of React, extending its features and optimizing the development process: React doesn’t even have to work with NextJS, but NextJS uses React to deploy applications.

React has a special framework – Create React App, an application used to create React projects and includes tools such as Babel, Webpack, and ESlint. Next.js is a React-based framework that allows you to build applications with server-side rendering. React is still the core of the application, but the structure and navigation mechanisms (architecture) – are defined by Next.js. The difference between a framework and a library is that a framework has more features and focuses on several aspects of development, and gives you rules and guidelines for writing code and structuring files.

Image description

Which one is better?

It’s hard to say that one is better than the other. Remember, React.js is a JS library – a set of tools you can use to build UI – and Next.js is a framework – the blueprints and rules you need to build an entire app – based on React so it’s not a pick this one instead of the other situation.

Use React when:

  • You need a highly dynamic routing
  • You’re already familiar with JSX
  • You need offline support

Use Next.js when:

  • You need an all-inclusive framework
  • You require backend API endpoints
  • You need server-side rendering

What do React vs Next.js projects look like

React

You can get started with React by installing Node.js on your machine and running npx create-react-app react-app. This will create a basic project structure with the src/App.js file as the entry point for the application. You’ll also have a public folder where you can store assets, and the initial scaffold looks like this:

Image description

Next.js

With Next.js, you can get started by running npx create-next-app next-app. This will scaffold out a project that already has a pagesfolder for the pages or routes and a public directory that hosts your assets. The initial scaffold looks like this:

next.js vs react

The files in the pages directory relate to routes in your application. The public directory stores your static files or images that you want to serve and can be directly accessed – no need to use require or other React traditional methods to import images into components.

Building Next.js and React projects with Flatlogic

The Flatlogic platform is a great way to bridge the gap between developing your applications. Applications usually use the same elements and components, when using the same technologies. The main thing that distinguishes them on a technical level is the database schema, which implements different data processing and storage mechanisms. The Flatlogic Platform allows you to create applications by combining parts and creating only those that need to be unique. Here you can see how to use the Flatlogic Platform to create Next.js, React applications, and other options for creating CRUD applications on the React. To generate your Next.js or React application, tap here and let’s go.

Step 1

Name your project and choose the tech stack: React as frontend and No-backend as backend.

Step 2

Choose the Starter Kit. Here you need to decide which starter kit is best for your project: Next.js or Create React App.

flatlogic platform

Next, you need to connect your GitHub repository and check the stack and starter kit and Finish the creation process.

next js apps

Then you will be redirected to the project settings where you will need to deploy your application.

Conclusion

React and Next.js are new and useful tools for your project, but only for certain tasks. When you choose Next.js, it offers the best solutions for server-side rendering and static website development. It also makes it easy to manage projects with a variety of tools and features.

On the other hand, React is the best choice for developing UIs for one-page applications. Being mobile and web-enabled, it works with a layer of mobile and web applications to create more appealing and intuitive ones. In a nutshell, Next.js offers various tools and features to minimize the development process while React has better resources for the frontend development of your mobile and web applications.

Top comments (1)

Collapse
joelbonetr profile image
JoelBonetR • Edited on

I'm a bit confused with this:

Use React when:
  • You need a highly dynamic routing
  • You’re already familiar with JSX
  • You need offline support
Use Next.js when:
  • You need an all-inclusive framework
  • You require backend API endpoints
  • You need server-side rendering

Reasons:

  • Next JS implements React. Anything that you can do with React is also possible inside Next JS the same way you'll use JSX inside Next frontend part (React).

  • The routing inside Next is based on file-system (easy to begin with, no config required like in React Router) and has the same flexibility at the end, or in other words, you can achieve the same with one or the other, it's just that in React (without Next) you need to manually define the routes.

  • The "offline support" is not provided in any case "as is", you'll need to code a web worker anyway. As example, you can also use next-pwa to have your app converted to a PWA easily which already implements a web worker.

  • Also note that most -serious- production react projects don't use CRA to begin with. CRA is just OK for learning purposes but getting all those opinionated generic dependencies, webpack as the only option and so on is not suitable for custom apps, where you set up the things regarding the project needs with a previous analysis.

I've been asked about the difference a couple of times, if I must, let me pin here a comment on that:

Hi @fyodorio it just depends on your needs.

Even if you've your services/micro-services on a different place, you can use the Server Side Rendering feature, this way your web app will be SEO-friendly.

Next Js is a framework (that implements React), so it brings a bunch of features on the top of it.

Maybe you find any feature that suits your project/s (Image or Fonts Optimisation, Routing, Static File Serving...). Also when dealing with more than a single project, using a framework can be a standard way to deal with those common tasks.

If you don't need (and analysis suggest you won't need in the future) SSR nor SSG and also you've the services somewhere else then maybe React is more suitable 😁

If it's the case and you go for React "only" I still recommend you to do a PoC with Next just to get some experience and find opportunities to use it later on.

So answering the question: Yes, it bring other sweet benefits, the question is if your specific project needs are aligned with what Next can offer πŸ™‚

Source

I understand that you're selling a product but it will be more convincing to me with a previous deep analysis πŸ˜…

Best regards

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.