Join egghead, unlock knowledge.

Want more egghead?

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

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Create Stream Behaviors to Push Props in React Components with mapPropsStream


    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.



    Become a Member to view code

    You must be a Pro 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
    orLog In




    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.

    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.

    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.