Stream Props to React Children with RxJS

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 years ago

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.

[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.