Create Stream Behaviors to Push Props in React Components with mapPropsStream

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 6 years ago

Rather than using Components to push streams into other Components, mapPropsStream allows you to create functions that can wrap components to create shareable behaviors across components.

[00:03] MapPropsStream allows you to create functions that will decorate your component, rather than creating a component itself. I'm going to create an interval here using MapPropsStream.

[00:13] It has a similar signature to our component fromStream, where it takes a function with a stream of props. We can props, switchMap, and use our props to return an observable.interval every one second. Then, as usual, use our selector here to take the props and the count that's back from our interval and return some props. Spread out the props and take that count.

[00:41] Now the props will have a count on it. This returns that stream of props. This does not map to a component like before, so we need to invoke it. I'll say counter with interval and invoke it. Interval and then pass in the counter down here. Now I can swap out counter to counter with interval. Save that, and you'll see the prop streaming in every one second, taking that count, and pushing it into the counter.

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