DEV Community

Cover image for Reactjs | Perfect tools for the perfect use cases🛠️💥
Kingkor Roy Tirtho
Kingkor Roy Tirtho

Posted on • Edited on

Reactjs | Perfect tools for the perfect use cases🛠️💥

React is awesome & one of the most wanted & most used JavaScript frameworks according to StackOverflow survey 2021. With React simplest to complex applications can be done easily. But there are so many reactjs based libraries that we often find "finding libraries" an overwhelming task. Many times, we can't even remember/guess the term related to that library making it way harder to find. So I present you all the perfect tools for perfect the use cases of React

I'm not going into full detail here. Just a simple introduction to the libraries that I mentioned or not at all. You'll find their docs more useful than this post/article/blog

State Management

A major part of React is state management. But there are 2 types of state management done in frontend UI libraries:

  1. UI state (e.g. UI schemes, light/dark mode, etc..)
  2. Data fetching/Async-data state (e.g. request-response caching, WebSocket event caching, etc..)

Many people don't even know that these 2 types of state management exist. They just give one solution Redux/Mobx/XState etc. But these are only UI state managers. Though some of 'em (e.g Redux) has Data fetching support through other packages/middlewares (e.g rtk-query) or have started recently, still it isn't complete

Data fetching/Network response caching requires caching, invalidation of outdated data, memoization, garbage collection, etc.. which are extremely hard to do manually through a UI state manager. Doing this with UI state managers can often lead to memory leak/high resource usage & other issues

Client-side state managers:

  1. zustand: A real simple, scalable, bearbones (barebone) state manager with no boilerplate but using the same FLUX principal. It's completely hooks-based & follows a single-store pattern. Though multiple stores can be created, all of them will be individual from each other. It's lightweight, fast, supports redux devtools, can be integrated with another awesome state-management pattern library immer & it supports middleware for stores. It's like the perfect state manager that React was missing
  2. Redux: The God of state managers. Every UI framework including Dart's Flutter is even supported by it. The pioneer library to implement the FLUX pattern. Redux changed the way of state management. Its performant, configurable, production-ready & provides robust API. Always proved its worth while being in larger production applications. But its boilerplate is overwhelming. Even being so great & useful, many people still hate it because of its huge boilerplate. Though redux-toolkit tried to mitigate that problem. But once you get off the first phase (boilerplate), I can guarantee you'll never regret that you used Redux
  3. MobX: Simple, scalable state manager & its framework agnostic. MobX even has Dart support. Its architectural freedom really lets one organize their state any way one wants. Just like Redux, it's battle-tested & production-proven. Its also store based & it mainly provides reactivity through Observables. Also, it's so much transparent & exposes the way it works to the end-user which is really uncommon compared to other libraries'
  4. recoil: Experimental warning! This state manager is from Facebook. It creates a graph for state attached to the React's tree & state changes flow from roots of this graph (which they call atom) through pure functions known as selectors & into components. It's boilerplate-free, simple, lightweight, compatible with Concurrent React (when this feature in react will be available) & provides ease of usability. It closes the gap that React's Context API can't do
  5. jotai: An awesome state-manager based on individual state pattern. Instead of creating a central store, it allows to create/manage state using individual atoms. And yeah, those states are called Atom. It's primitive, flexible, lightweight & super performant. It's from the same creator of zustand but with a different mental model. It's more close to recoil where zustand is close to Redux/MobX
  6. XState: An unique state management solution that uses the Finite State machine's concept."A finite state machine is a mathematical model of computation that describes the behavior of a system that can be in only one state at any given time". At first glance, xstate can be confusing but it'd all make sense once you get there. It's a neat state manager

Data fetching/Async-data management libraries:

  1. react-query: The missing data-fetching library for React, but in more technical terms, it makes fetching, caching, synchronizing, and updating server state in your React applications a breeze. Before react-query synchronizing with server state & caching was a neck-breaking job. Especially when you get only UI state managers. It removes the pain of managing memory, memoization, caching & outdated data invalidating manually. It's available for react-native too. It's one of the reasons why many developers choose React over other frontend frameworks
  2. swr: It's pretty similar to react-query. Provides hooks for data fetching & lightweight, supports JAM stack. Also transport & protocol agnostic. It provides fast page navigation, polling on intervals, data dependency, revalidation of cached data on focus, pagination/scroll position recovery & many more. It's from the same team of Nextjs & vercel
  3. apollo-client: A comprehensive state management library that enables one to manage both local and remote data with GraphQL. Can be used to fetch, cache, and modify application data, all while automatically updating your UI. It's like react-query but for GraphQL. Shares the same hook names too. But it's cross-framework compatible thanks to its community. It's the best Data-fetching library specifically for GraphQL
  4. rtk-query: It's from redux-toolkit & it's the best match if you're using Redux/redux-toolkit as your UI state manager. It's simple & lightweight. Unlike others, it's not store-based. So all requests are individual. As it is from Redux, you can expect production-grade performance too

Styling

Component styling is a very important part of any frontend project. The best way is of course with brae minimum CSS but time's most valuable so using some kind of framework or pre-built library is always a plus point

Styling using JavaScript is a new option too though it has an extra runtime cost but provides high customizability. Its called CSS in JS

Another way to keep the customizability freedom but cut off the runtime cost is to use CSS pre-processors. These're highly modular, customizable, offer easy-to-use syntax. And these finally get compiled to functioning CSS

CSS based:

  1. tailwindcss: Highly modular/configurable, utility first CSS framework. Has its own jit(Just in time) compiler to cut off unused CSS & push CSS styles on the fly in development. In production, can cut off 100% of unused CSS using purgecss. Almost anything that can be done through CSS can be done using tailwindcss classes
  2. bootstrap: Twitter's bootstrap is one of the best CSS component frameworks. For being over 10 years in the game, it's the most mature CSS framework. Best for quickly building user interfaces. Provides robust CSS classes that can be used to build any component. Bootstrap provides they're own component set. Also, there are tons of libraries built for bootstrap. So you'll never run out of custom component libraries
  3. scss: scss/sass is a CSS pre-processor that allows doing all cool stuff with a fairly easy syntax. Previously Sass's compiler was written in Ruby but later it was re-written in Dart. Scss/Sass is also the main building block of bootstrap where previously bootstrap was completely CSS-based
  4. css modules: Simply, CSS files in which all class names and animation names are scoped locally by default. It keeps the class names of that CSS file completely unique using UUID at the end of each class at build time. It's the best way to keep your component's styles individual from other's

CSS in JS based:

  1. styled-components: One of the best CSS in JS library. It allows styling using JS's new tag template function syntax. Allows theming, supports style inheritance, editor's CSS IntelliSense support, cross-compatible with other CSS frameworks & allows passing/accessing props through style functions/arguments
  2. emotion: Another CSS-in-JS library but its framework-agnostic. Offers high performance & ease of usability. It supports styling with both object & string. Emotion is really developer friendly & thus many bigger UI component libraries use it
  3. xstyled: It's a utility-first CSS-in-JS framework built for React. It makes it easy to consistent design system and scale it over time. Unlike other CSS-in-JS libraries, it allows one to style via passing props. It matches React's declarative term perfectly. Provides theming support. It's like tailwindcss but made with CSS-in-JS. But it isn't a complete CSS-in-JS library. It requires either styled-component or @emotion/react @emotion/styled as it uses them under the hood
  4. JSS: Another framework-agnostic CSS-in-JS library. It's simple, minimal & provides all the basic & barebones without any bloat & has a plugin system. It's a major choice for bigger UI component frameworks as it can do a lot if one can define it. Its also very lightweight

UI components

UI components are simply pre-built components that can be configured/tweaked for other design foundations. UI components save a lot of developer time & make the development easier. Also, its managed by so many people that they're often more secure & performant comparing to components built manually

So many UI component libraries are available. Many of them are completely individual & many are based on the philosophy & design pattern of bigger design systems

Here is the list:

  1. chakra-ui: Modular component library. It's like the tailwindcss of React but made with style as props pattern. Highly configurable theming support. Can be configured to look like anything & has a huge component library
  2. material-ui: The most famous UI component library in React ecosystem. Provides 200+ components, highly configurable & based on google's material-design principal. But currently, it's suffering from a Typescript type-related bug that makes the tsserver super slow to determine types. But it'll be fixed in the next major update v5 which is already in beta. This bug can slow down low-spec PCs easily but if you've got a mid-high spec PC then don't stop, use it. Also awesome if you're not using Typescript in your project
  3. react-bootstrap: React implementation of famous CSS framework bootstrap
  4. ant-design react: A UI component framework provided by ant-design for React based on the ant-design system. Highly customizable, supports theming & provides a huge number of components.
  5. grommet: Responsive, mobile-first, carefully designed UI component library for react. Has a large number of components. And their design is just beautiful. Simple, minimal & highly responsive
  6. evergreen: A flexible, contributor-friendly, sensible-default style providing UI component framework. Its foundation is super beautiful, provides a minimal design system & is unique among all

Info!: I'm building a UI component library based on tailwindcss which is gonna be a cross-framework library. At the start, react & vue support will be provided & svelte support is planned too. Its name is revind. And the project needs more contributors. If you want to contribute, head to https://github.com/revindjs/revind or contact me via Twitter

Form handlers

Handling Forms is a hard thing in react. Controlling, validating input, reset state on successful submit, checking whether the input was touched, etc.. are a lot of work to do. But luckily, there are form handling libraries that make it a breeze

List of form handlers:

  1. formik
  2. react-hook-form
  3. react-final-form

GraphQL

The graph query language provides a way to fetch only required data saving both user's & server's bandwidth. A technology by Facebook that sits on top of HTTP to work. It only uses the HTTP POST verb to transfer data. It's modern & makes HTTP connections more eco-friendly

Popular graphql libraries for React are:

  1. Apollo Client by Apollo Server
  2. Relay by facebook
  3. urql - universal react query library

Essential UI helper components/hook

1. Tables

Tables are most often needed for data-driven applications. But handling this amount of dynamic text manually can be a hazard. But these React Table libraries saves the day

List of table libraries:

  1. material-table (best if using material-ui)
  2. react-table (from the creator of react-query)
  3. MUI-Datatables (another best match for material-ui)
  4. react-virtualized (awesome for being framework-agnostic)

2. Animation libraries

Animations are now a modern trend. Every website/app has some kind of animations to make the end user's experience amazing. But creating such awesome animations isn't easy, it includes mathematics, algorithms & sometimes GPU acceleration too. But following react animation libraries made that work easy...

List of animation libraries:

  1. react-spring
  2. framer-motion
  3. remotion
  4. react-move

3. Loaders/Skeleton/Progress-bar

Always need a fallback when data is being fetched from the server, right? Showing loaders/skeleton/progress-bar makes it easier for users to wait & gives your site fewer "go away at first click" scores

Below are awesome loader libraries that can be used with React:

  1. react-content-loader
  2. react-loader-spinner
  3. react-spinners
  4. @tenem/react-nprogress
  5. react-loading-skeleton
  6. react-top-loading-bar

4. Infinite Scroll

Pagination is becoming an older way. Because of the increasing amount of smartphone users, it's now more convenient to use infinite scroll to get more data or an infinite amount of data. But doing so involves a lot of DOM manipulation via refs thus doing it manually is kind of a hazard. So infinite scroll component/hook libraries exist

List of infinite scroll component/hook libraries:

  1. react-waypoint
  2. react-infinite-scroller
  3. react-list
  4. react-infinite-scroll-component
  5. react-simple-infinite-scroll

Libreact

Another awesome react library is libreact. It's an awesome collection of all misc. react components that we don't need very often but sometimes become essential. libreact provides these components separately or as a collection. But either way, it almost contains all less essential components at the perfect time when we need 'em

Top comments (16)

Collapse
 
aantipov profile image
Alexey Antipov

And here I'm with my tool Moiva.io to help compare the libraries side-by-side:

Many charts and graphs with historical trends

Collapse
 
krtirtho profile image
Kingkor Roy Tirtho • Edited

You're the creator of moiva.io?! OMG!! Great, work bro❤️
Always keep it up for the open-source🔥🔥

Collapse
 
aantipov profile image
Alexey Antipov

Thank you! Will do my best :)

Thread Thread
 
iamjsonugo profile image
Johnson Ugo

Thank you so much for sharing your site.

Collapse
 
sargnec profile image
Necmettin Sargın

Can we get something similar for react native? This is awesome

Collapse
 
nimmio profile image
Nimmio

Great Post!

Collapse
 
imjituchauhan profile image
Jitu Chauhan

Thank you for sharing this amazing ReactJs product Tools.
We also build our first theme based on react bootstrap. Geeks UI.
Geeks UI - React Bootstrap based theme for developer and design agency.

Collapse
 
coderkari profile image
Md. Karimul Islam

awesome dude!!!!!!
I love this..

Collapse
 
hyggedev profile image
Chris Hansen

🦄 Brought attention of a few great resources to me. Thank you!

Collapse
 
peck0 profile image
Pedro Infante

Excelent

Collapse
 
gleisser profile image
Gleisser

Really useful! thanks!

Collapse
 
eneassena profile image
Enéas Senna

wow what a cool post.

Collapse
 
bryik profile image
Mohamed Bryik

amazing !!