LWC - Use Child Components When Rendering A List
Hello, I'm Brett with web developer.com. Since we're rendering a list of objects, and we want the formatting for each one to be the same, we're going to extract each thing that's being rendered in that list to a separate component. This will make it easier for us to glance at our HTML and see what's going on.
And it makes it more impossible. This be a bigger issue once we have more going on in our HTML. But for right now, since we only have a, we're displaying the name with a dash and the ID. We're going to take that and we're going to add it to a new component that I created. List object list item. Now add that into the template for the object list item somewhere since we took it out of the object list template.
Or we can select the second one, or the, whatever number one this one is. And it changes every time we select new. I know for the simple example, this doesn't seem like it'd be very useful. But when you have a repeat that is a complicated, structured HTML layout. Using a component inside the list to render it instead of composing it directly in the list, like say, if you're repeating a bunch of lightning design system cards on the page and I have complex HTML layouts, this would make it a lot easier to reason with, for what is happening for each one.
That’s it for now.
Remember to sign up for The Weekly Stand-Up! and you can get updated with any new information we have on WIPDeveloper.com.