What is up with this post?
This post might seem out of sync and the truth is that it somewhat is. I was just dealing with lists and then realized I've gone down the inexplicably stupid "generic list" road again somehow when I wasn't looking... Universe take the wheel, whee!
What is a list component?
Why, thank you for asking! It is a component that renders things from an array or a list (if using something more pythonic). If I was a gambler, I'd be willing to bet that if you've ever worked on user interfaces, you've seen something like ListRenderer or MyGloriousList components.
Seems reasonable enough at first sight, but it is a waste of time to make one. Why? Because at the end it is just a for loop and the newly built fancy ListRenderer or whatnot will attach special functionalities to the "for loop" at some point that (PAY ATTENTION HERE!) do NOT apply to all lists! And then all the other lists will have to change or take it into account.
What to do instead?
Instead of writing a list component, keep the for loop or a map and use other, more meaningful components to advance the functionality for a list of items. A common example is batch operations. Create a batch operator component and point it at a list of items that have checkboxes. Or make the batch operator into a simple button inside a form. Even better. A list just happens to be a number of sequentially ordered items, not something that will always have batch operators.
Same with ordering the list of items, filtering the items and so on - none of these are list component operations. They are operations that should happen before the list gets rendered. Typically even at a database level unless all the items of the dataset are available just before it gets rendered.
Operations applied to a list != rendering of the list.
What about my UsersList or CookiesList?
Those are fine as long as they render a specific type of data. My grudge remains with generic list components. Every time I see one, it has become this weird component that everybody hates, because it's less versatile than a 'for loop', but that has somehow become "the standard" that everybody must use.
Generic list components are not a good idea. Use a 'for loop' and compositional components inside of it instead of list-specific conditionals when generating the output. Life will be better.
- Heidi (Founder)