Next vs React
Tags: javascript, programming, react, nextjs
Published: 2022-05-28 16:40:32

This post was aimed mainly for novice programmers who haven't grokked on the frontend frameworks and libraries; I tried to make this post as easy to understand as a I could while making it very informative. My next post will be aimed more for experienced frontend devs: I will be diving more into Nextjs in my next post and by explaining in-depth some difficult things people struggle with, showing you step-by-step on how to not only create a nextjs app to but having a headless content management system (CMS) connected so the information that you show (products, blogs, etc...) can be changed dynamically using Sanity.io and have it Server Side Rendered (SSR) or Incremental Static Regenerated (ISR). **I will also explain all of this if you are not concrete about what was said** 👨🏻‍🏫

**What you will learn**: 

1. Understand what Next & React are and what they are used for
2. What are the similarity & differences between them
3. Which one to choose on a project

## Table of Contents

- [What is React](#WIR)

- [What is Next](#WIN)

- [Comparing and Contrasting React & Next](#CRAN1)

- [Which one to choose for a project](#WTC)

- [TL;DR](#tldr)


## <a id="WIR" href="https://reactjs.org/">What is React</a>

If you are familiar to web developing or programming in general, you have heard the term, React.js, being thrown around. **React** is a **library** that makes declarative UI _easier_ to accomplish using hooks and components. Essentially, you can write a chunk of code (mainly using jsx which is like html's sibling but cooler) into a one-liner(<Component />). It is **declarative** because the outcome of said component is predictable and easier to debug than imperative code. You also have these things called **hooks** that are **built-in functions** that make handling state, behavior and other logic easier to do in React in comparison to vanilla JavaScript. Also, you can write it anywhere in your project, (hence why React is a library and not a framework although people call it framework because it competes well to Angular and Vue) so you have more flexibility. It also has this thing called [Redux](https://react-redux.js.org/) which is a library that handles complex state management but we won't get into that 🤒 because there are __better and easier__ ways to manage state in React like using the [Context api](https://www.loginradius.com/blog/engineering/react-context-api/). I will go more into when to start learning React in a future post soon.

## <a id="WIN" href="https://nextjs.org/">What is Next</a>

Next is a **React framework** that was created by [Vercel](https://github.com/vercel/vercel) in October 25, 2016. Many big companies like Hulu even use it for their websites. It is a very very **good choice in building bigger applications** that have a lot more functionality and more complex state. Also, it comes with __a lot of features__ out of the box and I've linked the official Next website and talked about some of the features in the TL;DR section but besides those features it brings, it has a **structure** to it. React is a library so you might feel like you do not know where to start (most frontend devs haven't used a framework if you went the __tradition__ way of html, css, js and react) but Next solves that by having all the things React has, having little to no config with a shit ton of great features that will take you a while to make in React and having a structure built-in by default. This can be a pro or a con to some but if you are planning to make your first big project, I think Next would be a great decision and you would learn a ton about larger websites and how they work under the hood.

## <a id="CRAN1">Comparing and Contrasting React & Next</a>

I don't think they should be compared this way because both are extremely good at what they do. It really does **depend on what you are building** and I will dive a bit deeper in what questions you should be asking to yourself or others about what to choose when building your project so you can get not only the most out of it, but as fast and easy as possible. 

## <a id="WTC">What should I choose for my upcoming project?</a>

Firstly, you should understand what you want to build out first. Have a rough draft, like an essay, and see what libraries you might want to use; A good start to understand your project is to **ask these following questions**: Will your project have multiple pages with/without modular css for styling? Will it include state management? How complex will the state be for your website? Will it be a fullstack application? Are you planning to grow this project (CI/CD)? How important is it to have fast load times and do you care about SEO? Once you answered all these questions truthfully, it will give you a good indication on how big/small your upcoming project will be. 

## <a id="tldr">TL;DR</a>

React is a library based around **Component reusability** and uses hooks that have functionality like setting and updating state, having certain callback functions run at runtime and much more. I will make a React hooks post in the future covering all of the most used ones if you guys want me to.

Next is a framework that is built on top of React and makes **creating larger projects with more complex state easier to accomplish and maintain**. Since it has __built-in__ file-system routing, code-splitting, modular css, image optimization, etc... It is **ideal** for you if you truly care about how the data is fetched (SSR, ISR), care about SEO, and want to overall add a lot more functionality. It can be a bit overwhelming to conceptualize at first so I will go more into Next very very soon.

The best way to pick which would be better for your upcoming project is understand what you want to build. Is your project going to be a relatively lightweight project? Do you want the best load times possible if you are going to have information changing in short times? Am I going to CI/CD into a SaaS? These and a couple more questions would give you a good basis to decide which would be the best option for you.