Stream Props to React Children with RxJS

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 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.

egghead
egghead
~ 3 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today