If you hard-code a stream of props to target a specific prop, it becomes impossible to reuse that stream with any other components. Configuring your props stream with lenses will allow you to reuse your stream with any React component.

Checkout: lensProp, lensPath.

const personNameLens = R.lensPath([
"person",
"name"
]) const typewriter = lens =>
mapPropsStream(props$ =>
props$.switchMap(
props =>
Observable.zip(
Observable.from(R.view(lens, props)),
Observable.interval(100),
letter => letter
).scan((acc, curr) => acc + curr),
(props, name) => R.set(lens, name, props)
)
)
const DateDisplay = props => <h1>{props.date}</h1>
const dateLens = R.lensProp("date")
const DateTypewriter = typewriter(dateLens)(
DateDisplay
)

[Recompose] Make Reusable React Props Streams with Lenses的更多相关文章

  1. [Recompose] Compose Streams of React Props with Recompose’s compose and RxJS

    Functions created with mapPropsStream canned be composed together to build up powerful streams. Brin ...

  2. [Recompose] Configure Recompose to Build React Components from RxJS Streams

    Recompose provides helper functions to stream props using an Observable library of your choice into ...

  3. [Recompose] Merge RxJS Button Event Streams to Build a React Counter Component

    Combining input streams then using scan to track the results is a common scenario when coding with s ...

  4. [Recompose] Stream a React Component from an Ajax Request with RxJS

    Loading data using RxJS is simple using Observable.ajax. This lesson shows you how to take the ajax ...

  5. react Props 验证 propTypes,

    <body><!-- React 真实 DOM 将会插入到这里 --><div id="example"></div> <!- ...

  6. React——props的使用以及propTypes

    组件的props是只读的,组件不能修改自己的props,在React中,组件可以接受任意的props,如函数,对象,基本类型以及react元素 一.props的使用 1.一些组件并不需要知道自己的ch ...

  7. react~props和state的介绍与使用

    props是参数的传递,从上层模块向下层模块进行拿传递:而state是提局域变量,一般在本模块内使用,props是不能改变的,而state可以通过setState去修改自身的值. props Reac ...

  8. react props与render成员函数

    props是组件固有的属性集合,其数据由外部传入,一般在整个组件的生命周期中都是只读的,React的API顶层设计也决定了这一点.属性初值通常由React.createElement函数或者JSX中标 ...

  9. React props

    class WebSite extends React.Component { constructor() { super(); this.state = { name: "菜鸟教程&quo ...

随机推荐

  1. 用SqlDataReader返回多个结果集

    using System; using System.Data; using System.Data.SqlClient; namespace Northwind { class Program { ...

  2. MySQL常用技能篇

    写在之前的话: 之前一直在用MSSERVER,刚用MySQL时有很多的不适应.就此小结一下工作中遇到的问题和场景(用的不是很深入,供初学者参考),文中出现的局限性欢迎指出 MySQL有客户端式(SQL ...

  3. Session与Token认证机制 前后端分离下如何登录

     字号 1 Web登录涉及到知识点 1.1 HTTP无状态性 HTTP是无状态的,一次请求结束,连接断开,下次服务器再收到请求,它就不知道这个请求是哪个用户发过来的.当然它知道是哪个客户端地址发过来的 ...

  4. vue非父子组件间传参问题

    最近在使用vue进行开发,遇到了组件之间传参的问题,此处主要是针对非父子组件之间的传参问题进行总结,方法如下:一.如果两个组件用友共同的父组件,即 FatherComponent.vue代码 < ...

  5. CSS 清除浮动 伪类

    参考链接:https://www.cnblogs.com/yingsu/p/7261904.html 不清楚浮动的结果和影响不再描述,清除浮动的代码别处也有很多,每种方法都有十分简洁的代码,我今天学到 ...

  6. nginx proxy_set_header设置,自定义header

    在实际应用中,我们可能需要获取用户的ip地址,比如做异地登陆的判断,或者统计ip访问次数等,通常情况下我们使用request.getRemoteAddr()就可以获取到客户端ip,但是当我们使用了ng ...

  7. V$ASM_OPERATION

  8. C语言之文件操作04——输入矩阵a,b,求乘积c,并打印a,b,c到文件

    //文件与数组结合 /* ================================================================= 题目:输入矩阵a,b,求乘积c,并打印a, ...

  9. 使用bbed恢复表数据

    对于表级别的数据恢复,ORACLE提供了多种恢复方法:flashback query,logmnr等. 本文通过演示样例演示使用bbed的copy命令恢复用户误删除或者损坏的表数据,当然我们也能够使用 ...

  10. angularjs 服务供应商

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...