您的位置:首页 > Web前端 > React

[Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose

2017-12-28 03:26 423 查看
This lesson takes the concept of render props and migrates it over to streaming props by keeping the same example and simple refactoring the
Toggle
component which handles the render prop.

const ToggleStream = componentFromStream(props$ => {
const {
handler: toggle,
stream: toggle$
} = createEventHandler()

const on$ = Observable.merge(
toggle$,
Observable.interval(1000)
)
.startWith(true)
.scan(bool => !bool)

return props$.combineLatest(on$, (props, on) =>
props.render({
on,
toggle
})
)
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: