5 Tools for Building React Component Libraries in 2023

Learn what options are there to make your life easier when trying to create your own component library

Fernando Doglio
Bits and Pieces
Published in
7 min readMar 16, 2023

--

Building blocks, by LeonardoAI

As front-end development continues to evolve, React remains one of the most popular frameworks for building user interfaces.

One of the best ways to organize and share components built with React is through component libraries. That way you can centralize documentation, styles, maintenance, and literally everything related to the components. As opposed to releasing and manually sharing random components that you consider useful.

In this article, we will explore five tools that will help you build your own React component libraries in 2023.

Let’s go!

1. Bit

Bit.dev (or Bit as I’ll call it from now on) is a comprehensive platform that enables developers to build, share, and collaborate on React component libraries.

While it’s not solely focused on React, for the purpose of this article we’ll only care about that part.

Bit allows developers to either create from scratch or take existing code and turn it into what they call “components”. Why am I using quotes here? Because for them a component is not just the code you write to make it work, it also includes:

  • Documentation: Every Bit component comes with a default readme file and sample snippets that can be inserted and tried live inside the documentation (once published on their platform, bit.cloud). Find out more here.
  • Tests: Every Bit component is also accompanied by a set of tests that are automatically executed whenever a new version of the component is released.
  • Dependency management: Bit provides a dependency graph for each component. Within a Bit Workspace, you don’t need to tell npm, pnpm, or yarn which component dependencies need to be installed to, nor if its a dev or prod dependency. Bit dynamically generates package.json files for each, and can handle this for you painlessly. This guide will show you how.
  • Version control: Every Bit component is versioned for you. You can specify the version number when creating a new release or let the tool do it for you. This allows developers to update components in one project without affecting other projects that use the same component

And on top of that, given how Bit provides a central repository where you can publish and find components to reuse, it favors collaboration. All of this by abstracting complicated software such as Git behind their own CLI tool. This greatly simplifies the development workflow because all you have to remember are a few commands and the tool will do the rest for you.

If you’d like to know more, read this tutorial on how to use Bit to create your own UI library:

2. Storybook

Storybook is another popular tool designed to build React component libraries. It provides developers with the ability to develop and test components in isolation, making it easier to debug and iterate on individual components. Storybook includes several add-ons that extend its functionality, including support for testing and accessibility.

This option is particularly useful for generating automated documentation for components. This documentation includes examples, usage instructions, and even code snippets that can be copied and pasted directly into a project. Storybook has a rich ecosystem of plugins and integrations that makes it easy to customize and extend its functionality.

At a simple glance, you might be wondering what’s the difference between Bit and Storybook. After all, they’re both at the visual aspect of the component generation process. In other words, they’re both great at showcasing the components and adding very visually appealing documentation.

However, that’s pretty much all Storybook will do for you. There is no real support for versioning your components or even distributing them as you can do with Bit.

Mind you, if those aspects are not part of your goal or you’re OK with tackling those priorities with other tools, then Storybook is a fantastic solution, otherwise, it might lack some much-needed features.

3. Styleguidist

Styleguidist is a style guide generator. It enables developers to create living documentation for their components, providing an easy way to see how components look and behave in different contexts.

Granted, while you can’t build the actual components with Styleguidist, it’s also true that part of that development is creating the documentation for your library.

With Styleguidist you have all you need to create a very detailed documentation with minimum effort. Mind you, the more time you spend on it adding details, the more helpful it’ll be for other developers.

That said, you can point Styleguidist to your components and it’ll create the documentation by looking at different things:

  • The comments on your code and the doclet tags (i.e like getting external examples by parsing the URL on the @external tag).
  • The prop type notations from your component. Especially if you’re using something like Flow or TypeScript.
  • Any file called readme.md or componentName.md will be parsed and shown. If there are code blocks inside, they’ll be rendered as React components next to a playground which developers can use to tinker with the code and understand how each example works.

Styleguidist also supports popular styling frameworks like CSS-in-JS and SASS, providing a straightforward way to maintain a consistent look and feel across all components.

Overall, Styleguidist is a fantastic tool that will only cover part of the development of your React component library. If you’re using something else to take care of the rest, then go ahead and give it a try.

Did you like what you read? Consider subscribing to my FREE newsletter where I share my 2 decades’ worth of wisdom in the IT industry with everyone. Join “The Rambling of an old developer” !

4. Lerna

If you’re building a React components library, most likely you’re dealing with multiple packages (or components) inside the same repo. Ideally you’d want to publish all components together, but if you want to evolve each component individually and publish them separately, Lerna is a great tool to check out.

Lerna is a version control tool designed specifically for managing multi-package repositories. It enables developers to manage dependencies and versioning across multiple packages, making it easier to build and maintain large-scale component libraries.

One of the key benefits of Lerna is its ability to automate many of the manual processes involved in managing multi-package repositories.

This includes:

  • Automating versioning. You can simply run lerna version and it’ll ask you what part of the version to increase (using semver).
  • Publishing packages. With lerna publish all your packages are automatically sent to NPM. This is great help if you want to do multiple releases in parallel.

If you’re having to publish and maintain individual versions of your components inside your library, Lerna helps to make it simpler to keep them up to date and maintain a consistent workflow across all packages.

5. TSDX

What if you’re not looking for anything too complex? What if you just want to publish your simple TypeScript library but the simple idea of setting up the TS compiler, the bundler and the testing library makes your head hurt?

That’s where TSDX comes into play.

It is a simple, yet very powerful, no-code utility to help you set up your TypeScript project and manage it with a few commands.

With this tool, you can build your own React component library and get the following benefits out of the box:

  • Simple install and getting started steps (just create a new project with npx tsdx create react-lib ).
  • Linting integrated with eslint .
  • Testing included by the use of Jest.
  • Rollup as bundler.
  • Development mode with watch support, which means every time you change something the whole thing will be rebuilt.

By itself, TSDX provides a very simple workflow that you can follow to build and publish your library. It’s definitely not very complete and you lack aspects such as documentation or even collaboration if you’re not building this on your own. But if you’re not looking for anything more complex than transpilation, bundling and the occasional automated test, then TSDX might just be the thing for you.

In 2023, there are several powerful tools available for building React component libraries. Whether you need a comprehensive platform like Bit or a version control tool like Lerna, there is a tool to fit every project’s needs.

Granted, there are many other tools out there and I might’ve left the one you’re using out of the list. After all, given how the JavaScript ecosystem grows week after week, it’s impossible to cover everything in one list.

That said, if you have a recommendation I missed, please share it in the comments so others can know about it.

Build independent Design Systems and fully reusable Component Libraries with Bit

Bit’s open-source tool help 250,000+ devs to build apps with components.

Turn any UI, feature, or page into a reusable component — and share it across your applications. It’s easier to collaborate and build faster.

Learn more

Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:

Micro-Frontends

Design System

Code-Sharing and reuse

Monorepo

--

--

I write about technology, freelancing and more. Check out my FREE newsletter if you’re into Software Development: https://fernandodoglio.substack.com/