So, the only nice thing about it is it's very easy to type this. If you write TypeScript, then it's an object, it's very configuration-based, you can type the whole thing. But what ended up happening was folks wanted to put an icon here, put a count here on the right side. In the end, this is what the API started to look like, where there was a render item prop. Where it's a render prop, it's an inversion of control, we pass you the item props, and we say, please pass these to whatever you're going to render here. Because there's accessibility concerns here, there's a lot of magic that happens for focus and keyboard navigation, we want all of that to work, and we ask you to pass it back. I'm really afraid of something like render item, because we kind of lose all of the control or all of the features that we're big in and we're relying on the user to make sure all of that blue code for responsive design, for accessibility, they have set it up correctly, and they pass it down, right? I hate this. And especially this last pattern of render item, the problem with that is not that people would do mistakes, although it does happen, it's not like people are trying to break it. The idea is just that the component became so complicated with all the props that at some point we just had to declare prop bankruptcy and say, here's a function, you do it. I don't care. And that's like ejecting from a component, which kind of defeats the whole point. So all of that is actually a symptom of misunderstanding how flexible did we actually want the component to be, because if we did not want as many variations, it probably could still work, but I learned that we're probably further down here, even though we have all of the things that I said, it depends. But GitHub is big enough that there are so many contexts where the same component can appear. And it changes from component to component. So let's try this again with a slightly more flexible API in mind.
All right, so the answer that I went for is, let me try composition. Let me try to make a composite component. So there's an action list, like before, but instead of receiving an array of items, it accepts a child, which is action list.item. And .item knows how to render things the same way. And like before, you can attach more components onto one component, because it's all functions at the end of the day. So I can say, here's an item, and then action list.item is that component, and then people can use this nice composite API. So the nice thing is, like, on select is already on the item itself. This is probably where you'll guess to add it also, when you're selecting an element, you put the on select or the on click on it, so it makes sense. And then you have all of these items. I really like this so far, because it kind of makes sense. It looks tiny. It's not very confusing. Next step, dividers. If you wanted to if you had to guess what the divider would look like, what would you guess? Okay, three seconds. One, two, three.
Comments