45 NPM Packages to Solve 16 React Problems
Tags: react, javascript, npm, programming
Published: 2023-11-14 11:08:06

To read more articles like this, [visit my blog](https://www.mdfaisal.com/blog)

Note: This article is from 2 years ago. So, some of the technologies are outdated.

React is simply great. It’s popular and performant. But an important aspect of React is that it doesn’t come with all of the solutions packed in.

That’s why we need to search for additional libraries, which can be both good and bad. If you are a beginner, you must spend considerable time searching for the best solution to a problem.

Today, we will have a comparative discussion to learn more about the alternative solutions to different problems in react.

## 1. Global State Management

Sharing state between components is mandatory in 99% of the applications. And there are some good solutions — both native and external.

### Recommended

If you ask me for one solution, I will say **Redux**. Not because it’s the best but because it’s the most practical one. Many companies already use it, and you will have to use it at some point.

* [redux](https://redux.js.org/) with [react-redux](https://react-redux.js.org/)

Also the ecosystem is great as well. You can find a solution to almost any problem. Some great libraries that go with redux are:

* [redux-thunk](https://github.com/reduxjs/redux-thunk) -> For handling asynchronous action.

* [redux-persist](https://github.com/rt2zz/redux-persist) -> For storing data locally (offline support).

* [reselect](https://github.com/reduxjs/reselect) -> For making faster queries to store.

### Alternatives

* [jotai](https://jotai.org/) -> Excellent to handle almost all scenarios.

* [context](https://reactjs.org/docs/context.html) -> Built in to React. Good for simple use. Not good for performance. Especially if you have huge changing data.

* [recoil](https://recoiljs.org/) -> Designed to solve a specific problem. Not good for all use cases. Understand it first! You can learn more about it [here](https://javascript.plainenglish.io/state-management-in-react-with-recoil-984cfc1fcd63).

* [mobx](https://mobx.js.org/README.html) -> Follows observer pattern. Good for reactive programming. Shouldn’t be used in any new project.

## 2. Server State Management

If your application heavily relies on some external data source, then managing that data (caching, pre-fetching, etc) can be crucial for performance.

### Recommended

I am personally a huge fan of `react-query` and there are many others like me. It just works like magic.

* [react-query](https://react-query.tanstack.com/)

It handles `caching` stale data, and many more things out of the box. It’s simple, powerful, and configurable!

### Alternative

There is another player in the game named **SWR**. This is a similar library to React Query.

* [SWR](https://swr.vercel.app/)

The main benefit of this library is that it is built by Vercel. They are the same people who created NextJS. So you can expect better performance when using **NextJS.**

## 3. Scaffolding

[Creating a React app from scratch](https://betterprogramming.pub/complete-guideline-to-creating-a-modern-react-app-with-typescript-from-scratch-cebbb5817d8) is complex. Setting up Webpack, Bable, etc can be daunting!

### Recommended

[NextJS](https://javascript.plainenglish.io/start-your-journey-with-next-js-958705cfc299) is the choice for me when creating a React application from scratch. It is called the full-stack React framework.

* [NextJS](https://nextjs.org/)

In the documentation, it says,

>  Next.js gives you the best developer experience with all the features you need for production: hybrid static & server rendering, TypeScript support, smart bundling, route pre-fetching, and more. No config needed.

The most important feature of this is its out-of-the-box SEO support. Which is great! You can do [SEO in React](https://javascript.plainenglish.io/3-easy-ways-to-solve-seo-problems-in-react-applications-d3d7873dc494) as well. But it’s not straightforward like Next.

### Alternative

If you are starting with React or building some basic project, then you have other options.

* [create-react-app](https://github.com/facebook/create-react-app) -> Building a single-page application. Good for beginners.

* [gatsby](https://www.gatsbyjs.org/) -> Building static content-oriented website. Not good for other use-cases.
**Update: Gatsby is now outdated. You can take a look at Astro now.**

## 4. Form Handling

90% of web applications have some kind of form. And handling form inputs is a great pain. But we have some good news!

### Recommended

**React hook form** is the latest and greatest (according to me :P ) library for form handling. It’s really performant and flexible.

* [react-hook-form](https://react-hook-form.com/)

It has some good support with some external design libraries like `material-ui` and `ant-design` as well.

[**How to Use React Hook Form with TypeScript**
*Build Performant and Clean Forms for Your Application*javascript.plainenglish.io](https://javascript.plainenglish.io/how-to-use-react-hook-form-with-typescript-2cf597c0c45f)

### Alternatives

There are some good alternatives for this field.

* [Formik](https://formik.org/) -> Formik comes with battle-tested solutions for input validation, formatting, masking, arrays, and error handling.

* `redux-form` -> Don’t use it. It can really hurt the performance.

## 5. HTTP Call

In the modern world, almost all websites rely on some external data source. So making HTTP calls are very trivial.

### Recommended

Fetch is the recommended way to make HTTP calls.

* [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)

It has limited but powerful features. It can support 95% of your workload.

### Alternative

**Axios** is an improvement over fetch. It’s very popular.

* [axios](https://www.npmjs.com/package/axios)

It has some nice features like built-in XSRF protection and automatic JSON conversion and the ability to intercept HTTP calls. If you need that, you should go for it.

## 6. Styling

You are going to need styling. There is no doubt about that. There are multiple ways to style your application.

### Recommended

Many may not agree with me. But I think styled-components are the best choice when it comes to styling in React applications.

* [styled-components](https://styled-components.com/)

It helps to create clean components with a clear separation of concerns. Also, it’s easily manageable and configurable through props.

Also my new favorite now is [Tailwind CSS](https://tailwindcss.com/)

### Alternatives

However, as I said, there are other great alternatives!

* [plain old css](https://www.w3.org/Style/CSS/Overview.en.html) -> Supported out-of-the-box. It should be fine for smaller projects.

* [sass](https://sass-lang.com/) -> An improvement over CSS. It provides nice features for managing CSS. Good for mid-sized or even larger projects.

* [styled-jsx](https://github.com/vercel/styled-jsx) -> A library with a lot of similar features like `styled-components`. Has some extra features here and there.

## 7. UI Library

In many cases, designing all the components by hand may not be a good idea. In those cases, using some kind of UI library might be a good idea.

### Recommended

The most versatile and configurable UI library for me is the Material UI.

* [material-ui](https://material-ui.com/)

It’s very popular and used by many companies. It's highly configurable, which is why it’s so powerful.

### Alternatives

There are some good alternatives to check out as well.

* [semantic-ui](https://semantic-ui.com/) -> Many built-in components.

* [ant-design](https://ant.design/) -> Less configurable. Limited but nice components.

* [chakra-ui](https://chakra-ui.com/) -> Recently gaining popularity.

## 8. Documentation

Good documentation can save 100s of hours in the future. So be proactive and adopt a documentation library very early in the project.

### Recommended

The recommended way to create documentation is React StyleGuidist.

* [react-styleguidist](https://react-styleguidist.js.org/)

It's easy to use and really powerful.
[**Document Your React Applications The Right Way**
*Step by Step Introduction Guide*javascript.plainenglish.io](https://javascript.plainenglish.io/document-your-react-applications-the-right-way-f648053c3a70)

### Alternatives

There are some other alternatives, too.

* [js-docs](https://jsdoc.app/index.html) -> General documentation tool for javascript.

* [react-docz](https://www.docz.site/) -> Very easy to use documentation guide. Worth a shot.

## 9. Multi-Language Support

If you are building a product on a global scale, then you would probably like to add multiple language support in your React application.

### Recommended

**React i18next** is the de-facto option for [implementing multi-language support in React applications](https://javascript.plainenglish.io/implement-multi-language-support-in-react-9854c52ddb55).

* [react-i18next](https://react.i18next.com/)

* [i18next](https://www.npmjs.com/package/i18next)

### Alternatives

There are some other good alternatives as well.

* [react-intl](https://www.npmjs.com/package/react-intl)

This also has support for other libraries like VueJS and Angular as well.

[**Implement multi-language Support in React**
*In 6 easy steps*javascript.plainenglish.io](https://javascript.plainenglish.io/implement-multi-language-support-in-react-9854c52ddb55)

## 10. Animation

Animations bring your application to life. There are some good options to use animation in React.

### Recommended

Plain CSS is the best way to animate a React application. It’s simple and fast. Also, this is more performant.

* [Plain CSS Animations](https://www.w3schools.com/css/css3_animations.asp)

### Alternatives

If you want something that is ready-to-use then here are some recommendations for you

* [framer-motion](https://www.framer.com/motion/) -> Production-ready animation

* [react-awesome-reveal](https://www.npmjs.com/package/react-awesome-reveal) -> This is used for simple animations to reveal a component

* [react-spring](https://react-spring.io/) -> Another great and ready-to-use library.

## 11. Long List Render

Rendering a long list can hurt the performance of an application really badly. Using a library in this scenario can be a good idea.

### Recommended

If you have some kind of infinite-scrolling application then you should consider **React Window**

* [react-window](https://react-window.vercel.app/)

### Alternative

If you don’t need an infinite scrolling list then you can just paginate the data

* [react-paginate](https://www.npmjs.com/package/react-paginate)

[**How To Improve Rendering Performance in a 1,000-Item React List**
*Let’s ensure that our web apps scroll efficiently*betterprogramming.pub](https://betterprogramming.pub/how-to-improve-rendering-performance-in-a-1-000-item-react-list-85be129b8c0d)

## 12. Code Quality Tool

Linters can find any error in your code statically. It’s a good idea to use some kind of linter.

### Recommended

The go-to solution is Eslint

* [eslint](https://eslint.org/)

### Alternative

* [jshint](https://jshint.com/) -> Old library

* [tslint](https://palantir.github.io/tslint/) -> Linter for typescript. Not recommended now.

[**How to Add Linting and Formatting for your React App**
*Get this right, otherwise your code will have problems*javascript.plainenglish.io](https://javascript.plainenglish.io/how-to-add-linting-and-formatting-for-your-react-app-78227b328910)

## 13. Formatting

Having consistent visual styling is very important for any application and code-formatter can do that job for you!

### Recommended

* [Prettier](https://prettier.io/)

This is the greatest solution for you. You don’t need anything else!

## 14. Analytics

Data is the future. Most businesses today are data-driven. So having a good analytics tool for your application is very very important!

### Recommended

The most popular and powerful tool for the job is React Ga.

* [react-ga](https://github.com/react-ga/react-ga)

I don’t think you will need anything else.

[**How to Setup and Add Google Analytics to your React App**
*Google has made it really easy to gain insights into your web application*javascript.plainenglish.io](https://javascript.plainenglish.io/how-to-setup-and-add-google-analytics-to-your-react-app-fd361f47ac7b)

## 15. Testing

I don’t need to reiterate how important testing is for any application. So here you go.

### Recommended

The recommended way to go is React Testing Library

* [react-testing-library](https://testing-library.com/docs/react-testing-library/intro/)

It is very easy to use and designed to follow real-life use.

### Alternatives

* [jest](https://jestjs.io/) -> For unit tests

* [cypress](https://www.cypress.io/) -> For end-to-end test

[**Everything You Need to Get Started With Testing in React**
*A gentle introduction for beginners*betterprogramming.pub](https://betterprogramming.pub/everything-you-need-to-get-started-with-testing-in-react-e16819b0eba7)

## 16. Building sharable components

If you are in a large team then sharing components easily can become a great concern!

### Recommended

Storybook is the way to go if you are looking for the most complete solution

* [Storybook](https://storybook.js.org/)

That’s it. I think now you have a pretty good understanding of which library to choose when. Let me know if you have any different opinions.


**Have something to say? Get in touch with me via [LinkedIn](https://www.linkedin.com/in/56faisal/) or [Personal Website](https://www.mdfaisal.com/)**