[Recompose] Merge RxJS Button Event Streams to Build a React Counter Component
React to build Component Event button Merge Rxjs
2023-09-14 08:59:17 时间
Combining input streams then using scan
to track the results is a common scenario when coding with streams. This lesson walks you through setting up two buttons and merging their input events together to build a streaming Counter component.
const CounterStream = componentFromStream( props$ => { const { stream: onInc$, handler: onInc } = createEventHandler(); const { stream: onDec$, handler: onDec } = createEventHandler(); return props$ .switchMap( propos => Observable.merge( onInc$.mapTo(1), onDec$.mapTo(-1) ) .startWith(propos.value) .scan((acc, curr) => acc + curr) .map((value) => ({ value, onInc, onDec }))) .map( Counter ) } );
相关文章
- react父子组件传值示例「建议收藏」
- react promise使用方法
- 问:React的setState为什么是异步的?
- Mac下搭建React开发环境
- 学用Hooks写React组件——基础版Select组件
- React-hooks面试考察知识点汇总
- react源码解析14.手写hooks
- react源码分析--深度理解React.Context
- jsx和React.createElement是什么关系?面试常问
- 打造安全的 React 应用,可以从这几点入手
- React源码学习入门(十二)DOM组件更新流程与Diff算法
- react源码中的协调和调度
- To add browser notifications to an online customer support live chat service system - gofly - self h
- 这可能是你需要的React实战技巧_2023-03-15
- react 基础之组件篇二——Style in React