Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Stream Props to Multiple Children with React's Children.map and RxJS

    John LindquistJohn Lindquist

    Mapping the props to multiple children involves the use of React’s Children.map so that you can map over each child Component provided to the Parent Component stream. Inside the mapping function, you use the cloneElement and pass the props manually as you would with a single child component.

    reactReact
    ^16.0.0
    recomposeRecompose
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:00 When you declare a second counter and hit save, you'll see everything breaks, because the way we currently have it set up, there's a contract of only one element. To support multiple elements, we come into here and say, "Give me the children, static helper as well," and then we can use that.

    00:17 We'll return children.map, and loop through all the props.children. Then use a function which takes the child, and then clones each of those childs, or children, in the same way we did before. Now, you see we have multiple counters here and multiple counters down here.

    00:40 As long as this contract holds between a component that takes the value on ink and on deck. Then we can create whatever component we want. We'll call this weird counter, and this can be a span, this can be a span, this can be an h1.

    00:57 Then we'll drop a weird counter in here, weird counter. Now, we have a counter component that looks completely different, but it takes the same props. It works just the same as the other.

    Discuss

    Discuss