Skip navigation
❌ Avoid having components with too many props.
0:00 / 0:46

❌ Avoid having components with too many props.

George Moller

@_georgemoller117K followers

Visit on X
1,923 likesDownloadOriginal post

177,782 views

❌ Avoid having components with too many props. ✅ Instead use the compound components pattern in React to embrace composition.

10 Comments

Comments from the original post on X (Twitter)

  • George Moller's profile picture

    @_georgemoller

    I've been working professionally with React for more than 8 years and I compiled all my knowledge into 100+ infographics and 70+ video tutorials just like this one. Check them out ↓

    17 likes

  • wlepinski's profile picture

    @lepinski

    This is a really bad example of composition. You kind of allow the user to make a mistake like adding the icon in between the other components. If you want something similar you have to use renderProps.

    37 likes

  • George Moller's profile picture

    @_georgemoller

    I call that flexibility

    4 likes

  • tslamoon's profile picture

    @tslamoon1

    Meh. Yes use composition but this example Implementation isn’t that much better. It’s why we don’t have div and div.p and div.h1

    23 likes

  • React Nuclear's profile picture

    @reactnuclear

    This allows too much configurability. It’s better to use the interface of the component to guarantee the user won’t abuse how the component works internally. (“children: ReactNode” is basically an any)

    11 likes

  • Qui soc's profile picture

    @deincognito87

    Bad example of composition tbh

    6 likes

  • Snehil Kumar's profile picture

    @_sneakysensei

    Composition is good for an unopinionated component library where expectation is that devs will add custom styles. But it's a no-go for a product/brand's design system because they have rules set in stone for the sake of consistency Eg: "alert icon will always be on the top-left"

    6 likes

  • Stephen Rayner's profile picture

    @stephen_rayner

    Isn’t exporting as sub elements on the parent bad practice? Due to tree shaking limitations?

    6 likes

  • huda's profile picture

    @huda0816

    For me this does not make sense as I would have to change all the Alerts in my codebase if I want to change the Alert itself. If I wrap this in it's own component, I would have to pass all the props to the wrapper component.

    4 likes

  • Ndeye Fatou Diop 🚢 💻 | DEV | 🇸🇳🇫🇷's profile picture

    @_ndeyefatoudiop

    Love using this tip especially for the performance benefits

    3 likes