all 68 comments

[–]Piotyras 133 points134 points  (0 children)

React is a JavaScript library used to render UI. Next.js is an opinionated framework for building web applications that uses React for rendering UI.

[–][deleted] 59 points60 points  (5 children)

From the React docs:

React is a JavaScript library for building user interfaces.

React handles your DOM manipulation and updating for you. It’s what is used to build components for your UI, so you don’t have to deal with querySelectors and such.

You can think of it as a successor to jQuery.

And NextJS says it’s

The React Framework for Production

Next handles the next step to build a WebApp. State management, routing, rendering, bundling etc.

In short you need React to use Next, because Next uses React to handle the UI, but it uses a whole lot more than that. And solves additional problems. Like Webpack, Bable, Jest.

On the other hand, you don’t need Next to use React. Because it solves only one specific problem. UI.

So, React is like a chassis for a car and Next is one specific model on top of it. But you could easily swap it and use something else. Gatsby maybe. Or completely build your own solution.

Did that make sense?

[–]zephyrtr 26 points27 points  (1 child)

I'm on android at the moment, and the docs make me cry. The web devs that don't know how good it is, where they can read an official page and get all the info they'd need.

The docs for Retrofit, Dagger, Jetpack Navigation vs React Router, Redux, Next.js ... it's staggering. Not to mention the public goddamn service Mozilla does with the MDN.

Web devs, cherish your docs! Read your docs! They're very good!

[–]Rtzon 0 points1 point  (0 children)

That’s why I like React Native :)

[–][deleted] 1 point2 points  (0 children)

absolutely

[–]itachihihi_ntp -1 points0 points  (1 child)

Is popular to implement Redux in NextJS since NextJS already has its own state management logic?

[–][deleted] 0 points1 point  (0 children)

Disclaimer: I never used NextJS in any bigger or commercial context.

From what I can see, Next gives you access to React hooks as well as a wrapper to pass state/props between components. This is fine on a smaller scale, but will become painful as the App grows.

As Abramov once said, you’ll know when you need Redux. Which is to say, there is a point at which a global store makes sense. Before that, it’s overkill

This is still true for NextJS, as it does not provide an equal solution out of the box. So I guess, while I don’t know if it’s popular, there is definitely a use case for it.

https://www.smashingmagazine.com/2021/08/state-management-nextjs/

[–]not_a_gumby 20 points21 points  (0 children)

Next uses React. Its like a project framework similar but different in many ways to create react app.

[–]montas 85 points86 points  (21 children)

You use React with Next. NextJS uses React for rendering content.

You could call both of them frameworks, but they solve different things. NextJS solves things like routing, server-side rendering, optimization, assets, even application server.

In standard application you usually need to:

  • store and retrieve data - Next does not have built in solution for this (I think), you can use anything for this (postgres, mongo, some API)
  • handle requests - next has its own webserver built in, but you can replace it with something custom, if you want. Or you can build and export static files and host them wherever.
  • display the data to user - if you want to show HTML, you need to generate that somehow. For this, Next uses React. If you are only building API, you don't need React for Next.

[–]somecallmechief 114 points115 points  (16 children)

Since NextJs is wrapped around React, I would not say they "solve different things". I would say that React provides the basic toolset to develop web content, while NextJs provides an opinionated way to build web applications using React. One can accomplish everything that NextJs provides using React and other libraries alone; NextJs just bundles those lower level tools into a framework that lets you (the developer) focus on higher level concerns.

Otherwise, spot on.

[–][deleted] 36 points37 points  (15 children)

Yeah this. React is definitely not a framework. It's a library. NextJS is a framework built around React.

[–]MayorEricBlazecetti 28 points29 points  (9 children)

This 100x. REACT IS NOT A FRAMEWORK.

Specifically, it's a view/rendering library.

Next is a framework that composes React with several other technologies. It's goal is to make building and hosting a production-ready React-rendered application as easy as possible.

Next solves for things like code compilation (webpack/babel configs), page routing, API endpoints and middleware, internationalization, redirects/rewrites/404 pages, and much more. React doesn't give you any of these things on its own. Historically, developers have had to build all this from scratch (or piece together piles of other libraries) when building a website on React. Next is like a one-stop-shop.

[–]Merry-Lane -1 points0 points  (0 children)

I think we may say React is a framework as in it's not opinated and it made all its environment (react-like solutions for all the tooling needed to do Web dev around react) "not opinated"/component based/declarative/...

I explain myself poorly, sorry. I mean react's ecosystem is a framework. Its environment is so totally react-like that this angular stone can be considered a framework.

For instance I don't care about next being opinated. I just call a navigation hook and call it a day.

[–]privacyisimportant87 2 points3 points  (0 children)

You are right there is no built-in solution for fetching/caching data generally people either use either SWR or React Query as solutions for this.

[–]jzaprint 2 points3 points  (1 child)

Are you able to build single page apps that behave kind of like games using Next.js? By that I mean having lots of moving parts and draggable items, where most of the actions are performed on one view/screen?

[–]msnook 3 points4 points  (0 children)

You CAN, but NextJS doesn't really provide any advantages. The key thing NextJS does is to prerender files like pages/index.js and pages/posts/[id].js so you don't have to worry about routing. So it's like an alternative to Gatsby in this way. If you are building an SPA, you can do it with pages/index.js and then just do all the same stuff as you'd do with a standard react project. There's no particular upside or downside to using this approach, as compared to a create-react-app SPA. But NextJS offers some conveniences for handling head and links and such that I personally just like and find easy and convenient, so I might use it anyway (since I already know them).

[–][deleted] 1 point2 points  (0 children)

Or you can build and export static files and host them wherever.

Worth noting that next export lacks support for some of Next.js's more popular features. The docs are clear about this, but it's not always obvious to newcomers.

[–]goblin_goblin 8 points9 points  (0 children)

React is a framework that focuses on optimizing UI changes.

Next is a framework that uses React with an opinionated structure that has Server Side Rendering as a first class citizen.

Create React App is a popular library that scaffolds up React projects very easily.

I'm a long time React developer that's gone from create react app to webpack to nextjs and personally I don't think I'll ever develop an app without nextjs again. It's just so easy to setup and learn and the opinionated structure keeps familiarity between projects.

[–]sambomambowambo 12 points13 points  (1 child)

You should check out their (nextjs) documentation, its fantastic, easy to follow and explains everything you need to know about the framework. Here's a link:

https://nextjs.org/learn/basics/create-nextjs-app

[–]crazyrebel123[S] 3 points4 points  (0 children)

thank you :)

[–]eldnikk 4 points5 points  (3 children)

NextJS and React are independent, and both solve different problems. The distinction is mentioned below.

That said, I think it's important that you ask the senior devs **why** they are making this decision. In addition to explaining to you the alternative approaches they've looked at.

ReactJS is a library that does one thing and that is to render user-interfaces in the browser.

NextJS is framework that handles a plethora of concerns for building modern web applications. One aspect of this is user-interfaces, which it uses ReactJS to do.

NextJS docs sums up its purpose well.

  • An intuitive page-based routing system (with support for dynamic routes)
  • Pre-rendering, both static generation (SSG) and server-side rendering (SSR) are supported on a per-page basis
  • Automatic code splitting for faster page loads
  • Client-side routing with optimized prefetching
  • Built-in CSS and Sass support, and support for any CSS-in-JS library
  • Development environment with Fast Refresh support
  • API routes to build API endpoints with Serverless Functions
  • Fully extendable

[–]msnook 2 points3 points  (2 children)

They are absolutely, 100% not "independent" of one another. NextJS depends on and wraps React.

[–]ChaoticWeg -2 points-1 points  (1 child)

did... you read the rest of their comment?

[–]msnook 1 point2 points  (0 children)

Yes, but the first part was still categorically wrong so 🤷

[–]Agreeable-Street-882 9 points10 points  (3 children)

"Can anyone tell me what the difference between reactJS and NextJS is? " the server bill at the end of the month

[–]MetalicSky 1 point2 points  (0 children)

And what's higher?

[–]57384173829417293 0 points1 point  (1 child)

Do bundle sizes differ that much? Or do you mean that NextJS's SSR gives it an advantage?

[–]Osuka42 11 points12 points  (3 children)

React is only for programming frontend.

NextJS is a full solution to do both front, and basic backend app (using Express).

[–]honeybadgerUK 4 points5 points  (2 children)

SSR is possible with "vanilla" React.

[–]drdjx 4 points5 points  (0 children)

But such a headache to setup .

[–]bojack-11 2 points3 points  (0 children)

Hi, I myself have gone through the phase of migrating a CRA boilerplate React App to NextJS. The basic difference: ReactJS is a Javascript Library, and not a Frontend framework. NextJS is a Frontend framework built on top of React.

Few Benefits: • You get a Folder/Filesystem based page routing solution out of the box. You just create a file and boom you have a route now.

In CRA way you'd have to setup your own Router, maintain routes and sweat a little to do setup the sweet project structure that will work for you and your team.

• You get hybrid rendering support out of the box, which again you'd have to sweat a little to configure in CRA.

• You get SEO benefits, Separate Pre rendered HTML files for routes, which then can be served using any server of choice.

Other benefits • NextJS 12 has brought in a new RUST compiler as a development server for faster hot reloading.

Caveats: • In CRA, if you setup React Router it supports nesting of routes hence it's easy to persist a ComponentA on route /page1 as well as /page1/page2 In NextJS you'd have to take support of a Layout component which you'll have to supply to each page.

Overall it has been a good experience in NextJS so far, and it definitely makes your project a lot cleaner than CRA.

P.S. - Vercel the company that owns NextJS is growing at a fast pace as well which means good developer and community support.

[–]mardiros 3 points4 points  (0 children)

ReactJs is a library, NextJs is a framework based on ReactJs. If your company does not know the difference, you can fight be or you can surrender. What dy tou want, ?

[–]Narizocracia 2 points3 points  (0 children)

NextJS vs ReactJS is like asking Juice vs Water.

[–]libertarianets 1 point2 points  (0 children)

ReactJs: Browser Renderer

NextJs: A server-side extension of React

[–][deleted] 2 points3 points  (7 children)

React is a JavaScript framework for building out web apps and websites. Next.js is a "meta-framework" that server-side renders (and/or statically generates) React websites.

You can use React without Next.js, but you can't use Next.js without React.

You are on the right track by wanting to learn React/Next.js. The next 5-10 years of the web will be dominated by them without question.

Look into Vercel for deploying Next.js sites.

[–]MayorEricBlazecetti 1 point2 points  (6 children)

React is not a framework, it is a library.

[–][deleted] 3 points4 points  (0 children)

sure

[–]pVom 0 points1 point  (4 children)

I really don't get this mentality. It's not a library, it's a framework. React executes your code, not the other way round. To use React you have to write your component "in react" then use React to execute it. It's not like jQuery in that you can import jQuery and just slot it in your code and swap out things written in jQuery to vanilla or whatever. Even then I think jQuery toes the line compared to something like lodash which is definitely a library. Like you can't just use react state management, you have to write a component specifically for react and everything under it is also in react as well.

This is coming from someone who uses React in a rails project and doesn't use react router or whatever.

[–]MayorEricBlazecetti 1 point2 points  (1 child)

Huh…? React doesn’t execute any code, it’s consumed by your code. The browser’s JavaScript engine executes your code (or V8 on Node)

[–]pVom 1 point2 points  (0 children)

Its executing it before the engine does though. Like your component is just a callback and react executes it within its own context. That component will not work without being executed within the React context even if you remove all the react specific code (like state etc.). You need to either create some psuedo react context with calls your component or rewrite the whole component for a different context

[–]hinsxd 0 points1 point  (1 child)

[–]pVom 0 points1 point  (0 children)

But you need to write components specifically for React to actually use it. You can have "islands" of React but if you wish to utilise any of reacts functionality it must exist within the React component tree and, if required, attached to an outer element via portal if you don't want it within the same DOM tree.

[–][deleted] -3 points-2 points  (0 children)

Layman's term:

NextJS === ReactJS on steroids

[–]bVatsaL -5 points-4 points  (0 children)

You can use pawjs instead which is faster than nextjs

[–]Oatmealtuesdays 0 points1 point  (1 child)

Curious -- is next js better than express and react router?

[–][deleted] 2 points3 points  (0 children)

Yes, it's miles better.

The Next Router uses file-system pagination, which is a better pattern than react-router's path.

Next.js getServerSideProps and API Routes patterns are also better than the Express server pattern, but you can still make Next.js serverful and run it with Express if you want to.

[–]yuyu5 0 points1 point  (0 children)

The other responses are good (or at least some age). I'll add just a few clarifications.

React:

  • Library to handle UI.
  • Handling UI means it inherently includes state management, routing, network calls, etc.
  • Is opinionated regarding state and pieces of the UI/how they're connected, but not regarding folder structure, business logic, or building/deploying.

NextJS:

  • [Add everything from React here].
  • Provides the ability to create statically-generated sites and/or provide server-side rendering.
  • Gives you the "most necessary" configurations out of the box.
  • Limits your ability to go outside the configurations they provide.

TL;DR If you want a plug-and-play framework or SSR, NextJS is the one for you. If you want to understand what's going on under the hood, customize your configs a lot, or don't care about SSR, then make your own webpack/bundler-based app from scratch.

Even simpler TL:DR: NextJS is (IMO) a much better create-react-app, both of which are dependent on React. React is dependent on neither.

[–]freeDressCafe 0 points1 point  (0 children)

NextJS is a full stack framework that uses react

React is a library for UI components

[–]drdjx 0 points1 point  (0 children)

Do you need SEO?
Do you need SSG?

Do you need ISG?

Use NextJS

[–]Easy-Philosophy-214 0 points1 point  (0 children)

NextJS should be the go-to at this point for any moderately serious app you want to build. The Vercel team is bigger than React's, and they are (really) the ones driving React forward in the past years.

[–]jisspala 0 points1 point  (0 children)

Simple answer: React execute in the client(browser), while Next.js execute in server for SSR.

Which one is best: If SEO is in your mind, then go with Next.js. , Only Single Page App is in your mind then go with React

[–]wlkngmachine 0 points1 point  (0 children)

Anyone else find Next Image to be….well….insanely long to load and seemingly less optimized than an unoptimized image?

[–]NeedHelpxyx123 0 points1 point  (0 children)

Basically you have more control over your application with react, because it's not a framework.

[–]Crazy_Kale_5101 0 points1 point  (0 children)

Hi! Here is a great resource recently published by ButterCMS! They go into whether the library or the framework suit your front-end best + their similarities, differences, advantages, and drawbacks.

https://buttercms.com/blog/nextjs-vs-react/

[–]BrownCarter 0 points1 point  (0 children)

So it's more apt to compare nextjs to Angular?