Georg Unterholzner @georg.dev 路 Dec 5

My fellow web developers, where do you stand on this? When passing props from a parent to a child component/function, do you prefer: 1. Passing the object (reference) 2. Passing only the specific values needed?

3 likes 3 replies

?

Replies

Chris 馃 路 Dec 5

"It depends" But if I look at this example, I think I would prefer to pass the whole product. Potential complexity of the product definition aside, imo, it is intuitive to think about and generally more extensible.

Phendan 路 Dec 5

Fair question. I'd say if the number of props is manageable (let's say less than 5), I prefer to pass them individually to get a better idea of the actual data requirements and what the component might render without needing to dig through the implementation

Andreas 路 Dec 6

I tend to use 2. If there are common objects that need to be passed around I would rather rely on the child component to use a custom hook to get it itself. In this case all I need to pass down is the ID. TanstackQuery will make sure I don't fetch stuff twice.