Engineering

How to React in 2024, Part 1

Jan 26, 2024
6
MIN READ

As we step into 2024, React.js stands tall as the most popular tool for modern web development. With its massive user base, React has created a diverse ecosystem of libraries and frameworks built upon its solid foundation. In this first post of a two-part series, we will examine three of the most popular and innovative methods of working with React, discussing their advantages, disadvantages, and trade-offs. The upcoming post will cover three additional methods, continuing our exploration of cutting-edge approaches in the React ecosystem.

While huge ecosystems provide a lot of opportunities and solutions to common problems, the abundance can sometimes be overwhelming. In order to pick the right tools for the job, we usually need to take many things into consideration. Project requirements, security, performance, developer experience, and infrastructure costs are just some of them.

What is the process for setting up new React projects?

This is the first question that comes up when starting a new project. In the early days of React, this involved manually configuring bundlers, transpilers, task runners, and various other components. The process of setting up a project properly was often more complex than the apps we were building. Recognizing this challenge, the React team developed 'create-react-app', a comprehensive tool that streamlined this setup process.  This innovation significantly reduced the entry barrier, prompting a wider range of developers to experiment with and learn React, marking an important moment in the evolution of React and web development.

Today, the landscape has evolved further with the emergence of new tools that take developer experience to the next level. Let’s explore some of those tools to understand their impact on modern React project initialization.

Vite

Vite is a modern bundling tool for the web. It supports nearly every significant JavaScript/TypeScript framework. Out of the box, it gives us a lightning-fast dev server with hot module replacement (HMR), TypeScript, JSX, CSS support, and much more, all while being fully customisable. It's considered one of the favorite tools among the web development community.

A crucial aspect to remember when using Vite for React projects is that it's primarily utilized for developing Single Page Applications (SPA).

SPA is a web application that loads one HTML page and dynamically updates that page based on the user's interaction with the app. SPAs leverage JavaScript to create smooth, fast, and desktop-like applications without requiring page reloads.

The approach can be considered a traditional way of building React applications. This method, while having its own pros and cons, has been widely adopted and practiced over the years. Let’s explore some of the tradeoffs of this approach.

Pros

Cons

1. Use Vite as your bundling tool for all the reasons we mentioned previously.

2. For routing, there’s a proven, battle tested solution in the form of React Router. You could also explore TanStack Router. It’s recently gotten to version 1, and it has a lot of interesting features, with great support for TypeScript and URL query parameter management. It’s definitely worth a try.

3. Context APIs and core hooks like useState and useReducer can take you really far when it comes to managing your client state. For more complex use cases, Zustand is a pretty safe choice.

4. TanStack Query, formerly known as React Query, is an amazing choice for asynchronous state management, like data fetching. This is one of the most influential libraries in the history of React. It greatly simplifies the way we’re fetching and mutating server data.

Later in the article, we will explore some other interesting trends and recommendations that apply to all React-based projects, not only SPAs, so keep reading!

Overall, building React SPAs with Vite is a good choice when there’s no need for server runtime in our Fontend project. It gives us a lot of flexibility and is very simple to build and deploy. That makes them ideal for dashboard-like projects with high interactivity that don't require exceptional SEO.

Next.js

Next.js is a full stack web framework based on React. It’s one of the first server side rendering (SSR) frameworks in React’s ecosystem and definitely the most popular one. It popularized many modern paradigms in React and the web in general.

Next is created and maintained by Vercel, along with many experienced members of the original React core team. It has become the go-to choice for building React applications, establishing itself as one of the industry standard frameworks for web. Over the past decade, it introduced a lot of innovation, especially in the past few years with its implementation of React Server Components (RSC), which brought a lot of interesting features for React developers.

Pros

Cons

But what happens if we want to run it outside of Vercel for whatever reason? Well, if we wanted to follow a similar serverless model and have all the features of Next, like ISR, image optimization, streaming, etc., it would be very difficult to set up all of this ourselves. Thankfully, there is an open source project called OpenNext that lets us do all of that in a fairly simple manner on AWS infrastructure.

Another approach to deploying Next would be the traditional way of dealing with Node applications. Something like EC2 on the AWS cloud works just fine in most cases. The only issue with it is that our approach may not align with Vercel's vision for Next.js, which means that if we're not cautious, something could malfunction or become incompatible in the future.

Next.js is a remarkable framework that has significantly influenced React's history and development. It is versatile and fits well with most project types. Currently, Next.js is undergoing a major transition towards a new architecture, known as the "app router with RSC." While this architecture may not be completely ready yet, it holds great potential. Therefore, it's important to have confidence in its evolution and monitor its progress closely, as its future prospects look very promising.

Remix

Remix, like Next.js, is a full-stack web framework. The primary focus of Remix is on web standards and a fast, slick, and resilient user experience. It’s made by the team behind React Router, and it’s recently been acquired by Shopify.

Remix introduced exciting new features based on the existing web standards and APIs, boosted by the interactive capabilities of React. Its innovation has served as inspiration for various features in other frameworks like Next, SvelteKit, SolidStart, and more. Let’s explore some of those features.

Pros

Cons

In general, Remix is well-suited for projects of all sizes, domains, and complexities, offering out-of-the-box features, robust documentation, deployment flexibility, and, most importantly, focusing on empowering developers to create great user experiences.

Summary

React has reached heights that no other tool for building user interfaces has. We’re entering a new era of React with RSC, and we’re being enabled to do a lot more than before. I would argue that an average React developer will eventually become a full-stack developer. But with that comes a great deal of responsibility. Learning about performance, security, infrastructure, and software architecture in general has never been more valuable, because with these new models in React, we will need to apply that knowledge.

Now that we have learned how to get started with the React project, let’s figure out how to make it safe and maintainable on a language level. Head over to 'How to React in 2024, Part 2' where we'll uncover more innovative methods, provide insights, and explore further how React is shaping the future of web development.

Table of Contents
    AUTHOR:
    Marko Rusić
    Read more posts by this author.
    Back to Blog

    RELATED ARTICLES