[Recompose] Compute Expensive Props Lazily using Recompose
Learn how to use the 'withPropsOnChange' higher order component to help ensure that expensive prop computations are only executed when necessary. Simply specify which props are “expensive” and provide a factory function for those props.
withPropsOnChange(
shouldMapOrKeys: Array<string> | (props: Object, nextProps: Object) => boolean,
createProps: (ownerProps: Object) => Object
): HigherOrderComponent
Instead of an array of prop keys, the first parameter can also be a function that returns a boolean, given the current props and the next props. This allows you to customize when createProps() should be called.
const { Component } = React;
const { withPropsOnChange, withState, withHandlers, compose } = Recompose;
// only generate 'result' when depth changed
const lazyResult = withPropsOnChange(
['depth'],
({ depth }) => ({
result: fibonacci(depth)
})
);
const Fibonacci = lazyResult(({ result, color, size }) =>
<div style={{ color, fontSize: size }}>
Fibonacci Result:<br/>{ result }
</div>
);
[Recompose] Compute Expensive Props Lazily using Recompose的更多相关文章
- react recompose
避免写嵌套 import { compose } from "recompose"; function Message(props) { const { classes } = p ...
- [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 ...
- [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 ...
- SVM与LR的区别以及SVM的优缺点
对于异常数据,SVM比LR更好 SVM的优缺点: 优点:1.提供非常精确的分类器 2.更少的过拟合(因为有L2正则化项0.5||w||2),对噪声数据更加鲁棒(因为损失函数的原因) 缺点:1.SVM是 ...
- ML 激励函数 Activation Function (整理)
本文为内容整理,原文请看url链接,感谢几位博主知识来源 一.什么是激励函数 激励函数一般用于神经网络的层与层之间,上一层的输出通过激励函数的转换之后输入到下一层中.神经网络模型是非线性的,如果没有使 ...
- [Converge] Training Neural Networks
CS231n Winter 2016: Lecture 5: Neural Networks Part 2 CS231n Winter 2016: Lecture 6: Neural Networks ...
- react 使用的小建议
使用pureRender,setState和Immutable.js来操作state Immutable 中文意思不可变. 不能直接修改state的值,要用setState 和Immutable re ...
- Vue基础:子组件抽取与父子组件通信
在工作中承担一部分前端工作,主要使用Vue + Element UI. 随着版本迭代,需求增加,页面往往变得更加臃肿,不易维护.学习子组件的封装和抽取,能更好适应需求. 为什么需要子组件 可复用 将重 ...
- [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 ...
随机推荐
- chrome模拟手机功能
在搭建好web側环境之后.能够使用chrome来模拟手机的功能 直接上图吧: 图1是直接模拟一个通用的界面 图2里面能够选择不同的手机型号,还是比較全的! 选择一个查看一下,和手机是一样的效果,非常赞 ...
- JavaScript--数据结构之栈
4.1栈是一种高效的数据结构,是一种特殊的列表.栈内元素只能通过列表的一端访问,也就称为栈顶.后入的先出的操作.Last in First out.所以他的访问每次是访问到栈顶的元素,要想访问其余的元 ...
- liunx中安装禅道
本文转自:https://www.cnblogs.com/bendouyao/p/10026746.html 一.准备工作 禅道安装包ZenTaoPMS.8.1.3.zbox_64.gz,上传至服务器 ...
- C++基于矢量图形库cairo画图图形
//sudo apt-get install libcairo2-dev //pkg-config --cflags --libs cairo //-I/usr/include/cairo -I/us ...
- arukas 的 Endpoint
arukas 的 Endpoint 什么是端点 What is Endpoint arukas.io 的实例几乎每周都自动重新启动,当实例重新启动时,其端口会更改.IP地址和端口的平均寿命是一周,有时 ...
- 早该知道的 7 个JavaScript 技巧[转]
简洁写法 对象的简写在过去,如果你想创建一个对象,你需要这样: var car = new Object(); car.colour = 'red'; car.wheels = 4; car.h ...
- CentOS6.X安装10G需要额外安装的软件包
yum -y install libXp yum -y install libXp.i686 yum -y install libXtst.i686
- android之路Gallery 画廊
Gallery是一个内部元素能够水平滚动,而且能够把当前选择的子元素定位在它中心的布局组件. 我们还是直接看看样例的执行效果. watermark/2/text/aHR0cDovL2Jsb2cuY3N ...
- ajax中打开新页面使用window.open方法被拦截的解决方法
$('.testA').unbind('click').bind('click',function(){ var result=""; $.ajax({ url:'http://l ...
- 页面事件(Init,Load,PreRender)执行顺序
简介 对由 Microsoft® Internet 信息服务 (IIS) 处理的 Microsoft® ASP.NET 页面的每个请求都会被移交到 ASP.NET HTTP 管道.HTTP 管道由一系 ...