DEV Community

Discussion on: React component as prop: the right way™️

Collapse
 
adevnadia profile image
Nadia Makarevich

Not exactly. Even with element approach, the component is still rendered by the child. Parent will generate only this component's description, it will not trigger any of the lifecycle events, including render.

Check this out: codesandbox.io/s/buttons-with-icon...

I removed the icon from button's render, while still passing it from parent - and it's render is not triggered.

So the effect of that on parent will be comparable with creating an object there, and will be very cheap. Otherwise latest react-router wouldn't have been able to transition to this model: reactrouter.com/docs/en/v6/upgradi...

Collapse
 
kwirke profile image
Kwirke

Huh, interesting. Thank you very much for correcting me!
I'm pretty sure it worked like that in the past (but I could be wrong again). If that's the case, React has advanced quite a lot.