Developing and Driving Adoption of Component Libraries

Rate this content
Bookmark

What makes a component library good? In order to create a component library that people want to use you need to navigate tradeoffs between extensibility, ease of use, and design consistency. This talk will cover how to traverse these factors when building a component library in React, how to measure its success, and how to improve adoption rates.

This talk has been presented at React Advanced Conference 2022, check out the latest edition of this React Conference.

FAQ

A good component API should balance between flexibility and rigidity, aiming to cover the most common use cases (around 90%) while making it easy for developers to adapt to the remaining needs. It should provide ease of use, consistent outputs, and address complex challenges like accessibility and animation, which are often harder for developers to implement.

A rigid API simplifies the usage of the component library as it limits the ways a component can be misused, ensures consistency across different products using the same components, and is easier to implement and maintain.

A flexible API allows for a broader range of use cases, making it possible to tailor components to specific needs that may not be covered by a more rigid approach. This flexibility helps prevent teams from needing to create custom solutions that might detract from a unified look and feel.

The success of a component library at TikTok is measured using metrics like adoption rate and component coverage, which assess how frequently and effectively the components are used across projects. These metrics help determine the library’s impact on developer productivity and code quality.

TuxScanner is a static code analysis tool used at TikTok to analyze how components from the Tux library are utilized in codebases. It helps in gathering metrics such as component coverage and usage patterns, which are crucial for making informed decisions on library updates and improvements.

TikTok embraces regular breaking changes to ensure their component library remains optimal. They mitigate the impact by using a monorepo approach, ensuring most consumers are on the latest version, and by taking responsibility for updating consumer implementations during changes.

Logan Ralston
Logan Ralston
Lachlan Bradford
Lachlan Bradford
22 min
24 Oct, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's Talk discusses the importance of a good component API and the balance between rigidity and flexibility. The demo showcases the gradual evolution of a component's configurability while maintaining ease of use. Measuring the effectiveness of a component library involves factors like adoption rate and component coverage. Collecting data and embracing breaking changes are crucial for continuous improvement. Ensuring consumers are updated and on the cutting edge is a responsibility of the library provider.

1. Introduction to Component API

Short description:

Today, we'll discuss what makes a good component API. The API is the most important aspect of a component library. It can range from rigid to flexible, with each having its advantages. A rigid API is easy to use and ensures consistent outputs. It's also easier to implement. Now let's dive into the details.

Hi there, I'm Lachlan and today with my colleague Logan, we'll be talking to you about developing and driving adoption of component libraries. This will be broken up into two parts. First, I'll be speaking about what makes a good component API and second, Logan will be talking about how we measure the success of our own component library and how we use data to inform us of how we can better improve it for our users.

Quick introduction, I'm a tech lead at TikTok working on design systems and a maintainer of our internal component library called Tux. So I spend a lot of time thinking about component libraries and how our users interact with them. So first I'll ask what makes a good component library and from my point of view, the API is easily the most important thing. The way that developers interact with the library.

So what makes a good component API? So I found that APIs sit along a spectrum ranging from rigid to flexible. If you imagine a UI component, for example, a date picker, if we gave it a rigid API, there are some advantages to this. One is that if it's rigid and there are very few ways in which you can use it, it generally is very easy to use because there are very few ways in which it can be misused. Secondly, it has consistent outputs, meaning if multiple teams are using this component, it's very likely that they're using it in the same way and you'll get the same look and feel across the different products. Thirdly, and somewhat selfishly, it is a lot easier to implement a library that has a rigid API compared to one that is truly generic.

2. Approach to API Design

Short description:

We aim to cover the common 90% of use cases with a rigid API, focusing on solving hard problems like accessibility and animation. We recognize that we can't cover 100% of use cases, so we make the remaining 10% easy for teams to handle. If presented with a use case we can't support, we may consider opening up the API, but this can introduce breaking changes and impact consistency and complexity of the library.

On the other extreme, you could build a date picker in a very flexible way. And that would cover more use cases. This is also really important because if a component doesn't fit a user's needs, they might have to build their own or get one from open source. And as soon as they do that, you're potentially sacrificing the consistent look and feel that you're trying to achieve through having a rigid API.

So, our approach is we recognize you don't need to and can't really cover 100% of use cases. So, instead we aim for the common 90% and try to make the remaining 10% easy for teams to do themselves. So, therefore, we start near the left of the spectrum with a really rigid API that focuses on solving the hard problems. For example, accessibility features and animation. I call these problems hard because most front end developers don't have experience solving these problems and would rather spend their time working on things like application logic. We move further right along the spectrum as necessary. If we're presented with a really good use case that we can't support with our current API, we'll consider opening up the API somewhat. But this can involve breaking changes, which Logan will talk about later. We also need to be careful because moving right means we are potentially reducing consistency and increasing complexity of the library itself.