Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cons of next.js over create react app + redux + ssr [closed]

I have developed an application using React + redux + EJS (with server side rendering) and its running fine in production. I have configured SSR + redux and all the code splitting stuff using webpack config. I have also implemented custom cache middleware to cache the SSR rendered html string ( as needed).

Now, I have been told to refactor the code to suit next.js framework and was wondering the real need for that. What are the main advantages of using next.js if I have already figured out a way to do SSR without next.js framework?

I am not just asking an opinion rather I am trying to understand the real pros/cons of next.js (if any) over CRA.

I have uploaded the boiler plate here if anyone needed a reference: https://github.com/bbest123/reactreduxssr

like image 806
Learner Avatar asked Oct 24 '18 15:10

Learner


People also ask

Should I use NextJS without SSR?

js does not work without server-side rendering (SSR) by default. I preferred using a non-SSR solution like Create React App, when my app did not require SSR, because SSR had caused me so many unnecessary problems. Turns out Next is still 💯/💯, even if you only need index.

Should I use NextJS or create React app?

Should I Use Next JS or CRA? Typically if you have an application that will only be used behind a login, CRA is a good choice. However, if you have an application for which SEO is important and fast page loads are critical, then Next JS is the right solution.

Should I use Redux in NextJS?

The answer is no. You would be better off using some kind of query library like swr or react-query to manage the API data. So why would you fetch data and store it in the Redux store when you can get awesome features like caching and pre-fetching all without using Redux?

Is NextJS a SSR?

Next. js is a React framework built by Vercel (formerly Zeit) to make server-side rendering (SSR) easier for React applications regardless of where your data comes from. Next. js also supports static exporting and, newly, incremental static regeneration.


2 Answers

tl;dr

The only con (kind of) I can think of using Next.js is that it's opinionated. It would require you to structure things in a certain way which IMO is still quite extensible.

Advantages of using Next

  • Simple filesystem routing (plus client side routing with Link and prefetching capabilities)
  • Automatic code splitting for your pages (makes keeping bundle sizes in check simple)
  • Out of the box SSR with a simpler API (than implementing it yourself)
  • Exporting your app as a static site (provided you don't need to dynamically server render pages)
  • Simpler to extend your babel and webpack config (compared to a non-ejected CRA app)

All these things said, if you've already built your solution without Next.js and it works fine for your usecase, IMO there isn't a need to migrate to Next unless you are interested in abstracting some of the configurations and workings of SSR (which Next.js would take care of).

Relevant links

  • Issue on CRA discussing comparison with Next (a bit outdated)
  • Alternatives to CRA as suggested by CRA docs
like image 190
Divyanshu Maithani Avatar answered Oct 30 '22 05:10

Divyanshu Maithani


One of Nextjs' best features is huge list of 70+ list of implementation examples representing almost every combination of CSS framework, store (flux/redux/mobx/graphQL) framework, node servers, etc.

  • https://github.com/zeit/next.js/tree/canary/examples

It is possible to build a react SSR solution without Next.js, but the clean hooks for server-side logic (getInitialProps, pages/app.js, etc ...) are what makes Next.js a top choice here. Next.js shines here by allowing you to write clean, maintainable, and Performant SSR web applications.

Lastly, the development team & community is amazing!

like image 44
Efosa Avatar answered Oct 30 '22 04:10

Efosa