Join egghead, unlock knowledge.

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
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Stream Props to React Children with RxJS


    You can decouple the parent stream Component from the mapped React Component by using props.children instead. This process involves mapping the stream to React’s cloneElement with the children then passing the props in manually.



    Become a Member to view code

    You must be a Pro 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
    orLog In




    Import, from React, the function cloneElement. We can use this down where we map to our counter to instead take the new props, then say return clone element, grab the props.children off the old props, and then pass in the new props. Then, down in our JSX, instead of closing this tag, we'll close it down here and add a counter.

    Hit save there, and go up and down, because cloneElement took my counter, which I declared here, used it as children. and then passed in our new props. You can achieve the same effect using props and spreading it out into our map there. Then we can just name this one props and this one props, as well. That way, the children are carried along inside of this map. You can see this is still working.