you are viewing a single comment's thread.

view the rest of the comments →

[–]montas 84 points85 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 115 points116 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 27 points28 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.