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

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 years ago

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.

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.

egghead
egghead
~ 27 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