There's a faster version of egghead. Click here to try it.
1×
Become a member
to unlock all features
Autoplay

    Write Compound Components

    reactReact
    ^16.3.2

    Compound components give more rendering control to the user. The functionality of the component stays intact while how it looks and the order of the children can be changed at will. We get this functionality by using the special React.Children.map function to map over the children given to our <Toggle/> component. We map over the children to pass the on state as a prop to its children. We move the visual pieces of the component out into function components and add them as static properties to <Toggle/>.