Cons of next.js over create react app + redux + ss

2020-08-09 08:35发布

问题:

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

回答1:

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


回答2:

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!