This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Create Stream Behaviors to Push Props in React Components with mapPropsStream

    John LindquistJohn Lindquist

    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.

    reactReact
    ^16.0.0
    recomposeRecompose
    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    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.

    Discuss

    Discuss