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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose相关的知识,希望对你有一定的参考价值。

This lesson takes the concept of render props and migrates it over to streaming props by keeping the same example and simple refactoring the Togglecomponent 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
    })
  )
})

 

 

以上是关于[Recompose] Refactor React Render Props to Streaming Props with RxJS and Recompose的主要内容,如果未能解决你的问题,请参考以下文章

[Recompose] Lock Props using Recompose -- withProps

[Recompose] Transform Props using Recompose --mapProps

[Recompose] Add Lifecycle Hooks to a Functional Stateless Component using Recompose

[Recompose] Add Local State with Redux-like Reducers using Recompose

[Recompose] Add Local State to a Functional Stateless Component using Recompose

使用 recompose 和 typescript 正确键入 HigherOrderComponents