A colleague and I have a difference of opinion. Say a parent component rendering a list is using map to render a child component for each data object in the list (the data here is being stored in state).
My colleague insists only the id should be passed to the child component, and the child component does a look-up on the data stored in state to get the object.
I think, the parent having already looped through, should pass the entire object so the second look-up inside the child component can be skipped.
What's the general consensus out there?
Top comments (2)
Personally, I'd go with passing the data through props. Like you said the data is already there, so it makes sense to pass it right away. It would be an extra action to do a look-up, which isn't necessary in this case.
Keeping a component as simple as possible should be the goal. So by passing the object as a prop, the child will only do display whick keeps it very simple