DEV Community

Mignonne Maxwell
Mignonne Maxwell

Posted on

Should parent component pass object or just id?

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)

Collapse
 
murkrage profile image
Mike Ekkel

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.

Collapse
 
cairnswm profile image
William Cairns

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