Best practice for passing data as props into child? (React)

Lets say i have a loop in the parent component with an array of objects(mongo data) that renders a list of child component.

Should the children take each object as props or each key of the object as props?

basically:

<Child object={object} />

or

<Child key1={object.key1} key2={object.key2} .... />

?

Passing the object requires less code but it requires the child to know exactly what the key value names are when you make it, whereas passing keys the child doesnt have to know about the object key names at all.

1 Like

It depends on if you want to optimize for writing code fast or maintainability. The word “best practice” usually means maintainability, so I would suggest passing the keys individually.

1 Like