Little Bits of Iterative Component Design

Rate this content
Bookmark

What does a well-designed component API look like? Do you often find yourself forking components instead of extending them? Should you use props, hooks, or composition? In this lightning talk, I'll address common pitfalls in component design and share insights from my experience as a maintainer of Shopify's open-source framework, Hydrogen, and from building scalable design systems at Personio. By the end, I'll present a framework I use for iterating on and creating effective APIs.

This talk has been presented at React Day Berlin 2024, check out the latest edition of this React Conference.

FAQ

Daniel is a design system leader at Personio with an interest in rocks and math.

Composable components allow for mixing and matching, enabling the creation of flexible and reusable design elements.

YACNI stands for 'You Ain't Gonna Need It'. It encourages building only what is necessary, which can lead to faster shipping but also to technical debt and complex components over time.

A good API enables users to achieve their goals effectively. Poor APIs can frustrate users, be hard to roll back, and damage the creator's reputation.

Sharing feedback helps developers gain objective insights that they might miss, improving the overall quality of the API.

TC39 is known for creating new JavaScript APIs, such as Async/Await, through a thorough and lengthy process.

The CSS masonry layout discussion involves Apple and Google deliberating on the best API for handling edge cases in CSS masonry.

Daniel advises to enjoy the process of creating APIs, as there is never a perfect state for APIs, and to focus on iterative improvements.

Iterative component design is a process to develop APIs by prototyping, writing RFCs, and sharing for feedback, aiming to release a 'good enough' product.

Props in API design are simple and direct, making it easy for engineers to understand and use, especially when using TypeScript.

Daniel Rios Pavia
Daniel Rios Pavia
10 min
13 Dec, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Hey, everybody. My name is Daniel, and I like rocks. I'm a design system leader at Personia and something that I do like that is also a bit nerdy is math. I like math. There's many ways to solve a problem. One way to build it in an API is to make it with props. The next possible way could be composable components. Which one is better? Senior engineer answer would be, well, it depends. Props are really good with TypeScript. On the other hand, composition... You could have other types of components. You could create other types and put them and still work. Let's say I want to wrap it in a tooltip. You can see a bit of the differences in approach. This is a masonry layout. What kind of strategies can I use as an engineer for making my own decisions? One that I know is this one called YACNI. Over time, this creates tech debt. If you make a little bit of effort and make this reusable, it can go a long way in terms of API. And then the special situation that you want to handle just handling outside. At some point in my career, I was using a lot of YACNI and I started to work at Shopify in an open source project and I started to care about the APIs that I released because they are supposed to enable people to do the things they want to do and if it doesn't happen, then it's really sad. It's the same with design systems. If you make an API that is not good, there's a cost to it. How can I make good APIs? Let's see some of the big ones. TC39, they are the group that's actually creating the new JavaScript APIs. I made my own process that I call iterative component design where I try to figure out what is good enough for a release before putting it out. The step one is to prototype. And this is, again, doing Yagni. I think you can have better APIs if you follow a proper process. Second step, I usually write an RFC. When you do this, you realize what parts of your API sound really weird to explain. And the final step here is to share. Sharing is difficult because sometimes we have pride as developers and we don't want to take feedback and we just want to release immediately. But the problem with not getting feedback is that when you're working with a problem, you're unable to see objectively anymore. Sharing is good. All the APIs, there's never a state of nirvana for APIs. There's always feeling like something is not right, something is broken here. All my time working, I felt that we never got there and probably we will never. So all you can do is probably enjoy the process of creating APIs. That's my final advice. Thank you.

1. Introduction to Rocks and Math

Short description:

Hey, everybody. My name is Daniel, and I like rocks. I'm a design system leader at Personia and something that I do like that is also a bit nerdy is math. I like math. There's many ways to solve a problem. One way to build it in an API is to make it with props. The next possible way could be composable components. Which one is better? Senior engineer answer would be, well, it depends. Props are really good with TypeScript. On the other hand, composition... You could have other types of components. You could create other types and put them and still work.

♪♪ ♪♪ ♪♪ ♪♪ ♪♪ Hey, everybody. My name is Daniel, and I like rocks. In fact... It's a picture of me in Iceland with somebody that collected a lot of rocks. Not me. I'm a design system leader at Personia and something that I do like that is also a bit nerdy is math. I like math. Why do I like this nerdy thing? It's because in some way, it's a very exact science and I like that there's usually an optimal solution to everything we do. I guess software engineering... Yeah. There's so many opinions, always. There's many ways to solve a problem.

For example, let's say we wanted to build a drop-down component like this one. One way to build it in an API is to make it with props. I have the props have label. This is simple, and I think most engineers will use this because I feel that engineers like props. It's just very direct. The next possible way could be composable components. You could have this drop-down, have these sub-components and then just put them together. What's really nice is that you can mix and match them. I'm seeing this more often in design systems. Which one is better? Which one do you think is better? Senior engineer answer would be, well, it depends. Right? Let's analyze. Props are really good with TypeScript. When I'm writing it, it's really nice to see what's happening. I need to put a value here and then, okay, it appears. You can easily, on the fly, understand it. On the other hand, composition... You could have other types of components. You could create other types and put them and still work.

2. Building Reusable Components with YACNI

Short description:

Let's say I want to wrap it in a tooltip. You can see a bit of the differences in approach. This is a masonry layout. What kind of strategies can I use as an engineer for making my own decisions? One that I know is this one called YACNI. Over time, this creates tech debt. If you make a little bit of effort and make this reusable, it can go a long way in terms of API.

Let's say I want to wrap it in a tooltip. I can do that. It will still work. You can see that there's a lot of mixing and matching happening. On the other side, with the props, it will be a bit difficult. You end up creating these huge objects to be able to get the same thing. You can see a bit of the differences in approach. What I mean by this, there's always pros and cons, even on the little things. Also, on the big things, there's a lot of pros and cons.

If anybody knows, this is a masonry layout. Recently, there's a CSS masonry API proposal. This is the discussion that's happening between Apple and Google on what is the best API for CSS masonry. It's just a lot of edge cases to handle. Even bigger situations have trouble deciding what's the best API for work. We go back. Software engineer has a lot of answers. What kind of strategies can I use as an engineer for making my own decisions? One that I know and probably you all know is this one called YACNI. You hear YACNI there, YACNI that. Whenever somebody asks you why this is happening, you can just tell them YACNI. For those that don't know, YACNI means you ain't gonna need it. You just build exactly what you need and just ship it. You just ship fast, really, really fast. Your performance review comes out really exceptional. As you guessed, over time, this creates tech debt.

One example of using YACNI on this simple component that has an icon is now I need a flag, I add a flag prop. Now I need some error and a warning and a color maybe, and I need to add a tooltip and then have some boolean for some special situation so that this component behaves well. You can see that this ends up being a Frankenstein component over time. If you make a little bit of effort and make this reusable, it can go a long way in terms of API. For example, this component could have an accessory that can receive flags, icons, and other stuff that not only does, and the colors could be semantic. And we can have a reusable tooltip component that can be used in other areas as well.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Get rid of your API schemas with tRPC
React Day Berlin 2022React Day Berlin 2022
29 min
Get rid of your API schemas with tRPC
Today's Talk introduces TRPC, a library that eliminates the need for code generation and provides type safety and better collaboration between front-end and back-end. TRPC is demonstrated in a Next JS application integrated with Prisma, allowing for easy implementation and interaction with the database. The library allows for seamless usage in the client, with automatic procedure renaming and the ability to call methods without generating types. TRPC's client-server interaction is based on HTTP requests and allows for easy debugging and tracing. The library also provides runtime type check and validation using Zod.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.
Handling Breaking Changes in GraphQL
GraphQL Galaxy 2022GraphQL Galaxy 2022
22 min
Handling Breaking Changes in GraphQL
Top Content
This Talk discusses handling breaking changes in a GraphQL schema, including the use of the deprecated directive to tag fields that should no longer be used. It also covers the process of deploying GraphQL APIs and mobile apps, highlighting the challenges of mobile app release adoption. The Talk emphasizes the importance of making safe upgrades in mobile apps and provides strategies for detecting and handling breaking changes, such as using TypeScript and GraphQL Inspector. Overall, the Talk emphasizes the need to minimize user impact when introducing breaking changes in GraphQL schemas.
Advanced Patterns for API Management in Large-Scale React Applications
React Advanced 2021React Advanced 2021
20 min
Advanced Patterns for API Management in Large-Scale React Applications
Top Content
This Talk covers advanced patterns for API management in large-scale React applications. It introduces the concept of an API layer to manage API requests in a more organized and maintainable way. The benefits of using an API layer include improved maintainability, scalability, flexibility, and code reusability. The Talk also explores how to handle API states and statuses in React, and provides examples of canceling requests with Axios and React Query. Additionally, it explains how to use the API layer with React Query for simplified API management.
Safely Handling Dynamic Data with TypeScript
Node Congress 2021Node Congress 2021
29 min
Safely Handling Dynamic Data with TypeScript
Top Content
This Talk discusses the safe handling of dynamic data with TypeScript using JSON Schema and TypeBox. Fastify, a web framework, allows developers to validate incoming data using JSON schema, providing type safety and error handling. TypeBox is a powerful library that allows developers to define JSON schemas and derive static types in TypeScript. The combination of JSON schema, TypeBox, and Fastify provides powerful tools for type safety and validation of dynamic data.
APIs are Evolving. Again.
JSNation 2023JSNation 2023
28 min
APIs are Evolving. Again.
Matteo Collina
Luca Maraschi
2 authors
Technology is a spiral, with foundational ideas resurfacing. Java revolutionized enterprise applications. REST and JSON simplified building APIs and websites. Node.js enabled fast and custom development, leading to the microservices revolution. Platformatic aims to fill the gap in building, managing, and scaling microservices painlessly.

Workshops on related topic

Hands-on with AG Grid's React Data Grid
React Summit 2022React Summit 2022
147 min
Hands-on with AG Grid's React Data Grid
Top Content
WorkshopFree
Sean Landsman
Sean Landsman
Get started with AG Grid React Data Grid with a hands-on tutorial from the core team that will take you through the steps of creating your first grid, including how to configure the grid with simple properties and custom components. AG Grid community edition is completely free to use in commercial applications, so you'll learn a powerful tool that you can immediately add to your projects. You'll also discover how to load data into the grid and different ways to add custom rendering to the grid. By the end of the workshop, you will have created an AG Grid React Data Grid and customized with functional React components.- Getting started and installing AG Grid- Configuring sorting, filtering, pagination- Loading data into the grid- The grid API- Using hooks and functional components with AG Grid- Capabilities of the free community edition of AG Grid- Customizing the grid with React Components
Building GraphQL APIs on top of Ethereum with The Graph
GraphQL Galaxy 2021GraphQL Galaxy 2021
48 min
Building GraphQL APIs on top of Ethereum with The Graph
WorkshopFree
Nader Dabit
Nader Dabit
The Graph is an indexing protocol for querying networks like Ethereum, IPFS, and other blockchains. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.

In this workshop you’ll learn how to build a subgraph that indexes NFT blockchain data from the Foundation smart contract. We’ll deploy the API, and learn how to perform queries to retrieve data using various types of data access patterns, implementing filters and sorting.

By the end of the workshop, you should understand how to build and deploy performant APIs to The Graph to index data from any smart contract deployed to Ethereum.
Database Workflows & API Development with Prisma
Node Congress 2022Node Congress 2022
98 min
Database Workflows & API Development with Prisma
WorkshopFree
Nikolas Burk
Nikolas Burk
Prisma is an open-source ORM for Node.js and TypeScript. In this workshop, you’ll learn the fundamental Prisma workflows to model data, perform database migrations and query the database to read and write data. You’ll also learn how Prisma fits into your application stack, building a REST API and a GraphQL API from scratch using SQLite as the database.
Table of contents:
- Setting up Prisma, data modeling & migrations- Exploring Prisma Client to query the database- Building REST API routes with Express- Building a GraphQL API with Apollo Server
Best Practices and Patterns for Managing API Requests and States
React Advanced 2022React Advanced 2022
206 min
Best Practices and Patterns for Managing API Requests and States
Workshop
Thomas Findlay
Thomas Findlay
With the rise of frameworks, such as React, Vue or Angular, the way websites are built changed over the years. Modern applications can be very dynamic and perform multiple API requests to populate a website with fresh content or submit new data to a server. However, this paradigm shift introduced new problems developers need to deal with. When an API request is pending, succeeds, or fails, a user should be presented with meaningful feedback. Other problems can comprise API data caching or syncing the client state with the server. All of these problems require solutions that need to be coded, but these can quickly get out of hand and result in a codebase that is hard to extend and maintain. In this workshop, we will cover how to handle API requests, API states and request cancellation by implementing an API Layer and combining it with React-Query.
Prerequisites: To make the most out of this workshop, you should be familiar with React and Hooks, such as useState, useEffect, etc. If you would like to code along, make sure you have Git, a code editor, Node, and npm installed on your machine.