Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

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

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Stream Props to React Children with RxJS

    John LindquistJohn Lindquist

    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.

    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

    00:00 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.

    00:28 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.

    Discuss

    Discuss