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. CDR X6设计师的福利,3折特惠!

    最新消息称,即日起CorelDRAW官方为回馈新老用户长期以来的支持,特别推出CorelDRAW X6降价活动.目前CorelDRAW X6售价仅为2399元,照这个价格,CDR 2017     会 ...

  2. Mathab和Python的numpy中的数组维度

    Matlab和Python的numpy在维度索引方面的不同点: 1.索引的起始点不同:Matlab起始位置的索引为1,Python为0. 2.索引的括号不同:Matlab中元素可以通过小括号表示索引, ...

  3. 在Scrapy中如何利用Xpath选择器从HTML中提取目标信息(两种方式)

    前一阵子我们介绍了如何启动Scrapy项目以及关于Scrapy爬虫的一些小技巧介绍,没来得及上车的小伙伴可以戳这些文章: 手把手教你如何新建scrapy爬虫框架的第一个项目(上) 手把手教你如何新建s ...

  4. 永远不要在MySQL中使用“utf8”

    最近我遇到了一个 bug,我试着通过 Rails 在以“utf8”编码的 MariaDB 中保存一个 UTF-8 字符串,然后出现了一个离奇的错误: Incorrect string value: ‘ ...

  5. c traps and pitfalls reading note(1)

    1. 一直知道char *p = 'a';这样写是错误的,但是为什么是错的,没想过,今天看书解惑. p指向一个字符,但是在c中,''引起来的一个字符代表一个整数,这样指针能不报错.o(^▽^)o 2. ...

  6. 紫书 例题8-14 UVa 1607 (二分)

    题意非常难理解-- #include<cstdio> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namesp ...

  7. window下搭建Python3.7+selenium3.1.1+pycharm环境

    1.安装Python3.7 1.1  下载 Python并安装 Python3.5 (勾选上 Add Python3.7 to PATH) 点击 Install Now,安装完成后将python路径加 ...

  8. Qt之图形(QPainter的基本绘图)

    简述 Qt中提供了强大的2D绘图系统,可以使用相同的API在屏幕和绘图设备上进行绘制,它主要基于QPainter.QPaintDevice和QPaintEngine这三个类. QPainter用来执行 ...

  9. hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)

    题目链接:pid=5137">点击打开链接 题目描写叙述:如今有一张关系网.网中有n个结点标号为1-n.有m个关系,每一个关系之间有一个权值.问从2-n-1中随意去掉一个结点之后,从1 ...

  10. java 基本类型、包装类、字符串之间的转换

    1.基本类型和包装类 基本类型和包装类可通过自动装箱和拆箱实现. int i = 24; Integer a = new Integer(i); //手动装箱 Integer b = i; //自动装 ...