[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 ...
随机推荐
- js12--块作用域函数作用域
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- c#的中英文混合字符串截取
public class StringHelper { public static string GetSubString(string str, int len) ...
- HDU——T 2824 The Euler function
http://acm.hdu.edu.cn/showproblem.php?pid=2824 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- 洛谷——P1781 宇宙总统
https://www.luogu.org/problem/show?pid=1781 题目背景 宇宙总统竞选 题目描述 地球历公元6036年,全宇宙准备竞选一个最贤能的人当总统,共有n个非凡拔尖的人 ...
- Jquery获取select选中的option的文本信息
注意:以下用的$(this)代表当前选中的select框 第一种: $(this).children("option:selec... ...查看全文
- ShopEx 中规格属性添加时,自己主动计算其相应的销售价格,同一时候注意模板中的变量间的计算
在ShopEx中,添加产品的规格时,如颜色.尺寸.是否送货等配置信息,默认情况下,这些内容是须要手动计算的,若仅仅有几个属性值还easy计算,假设每个属性值比較多,通过手动计算将是一个灰常巨大的工作量 ...
- 利用 istio 来对运行在 Kubernetes 上的微服务进行管理
尝试在一个准生产环境下,利用 istio 来对运行在 Kubernetes 上的微服务进行管理. 这一篇是第一篇,将一些主要的坑和环境准备工作. 内容较多,因此无法写成手把手教程,希望读者有一定 Ku ...
- 使用@Order调整配置类加载顺序
转自:https://blog.csdn.net/qq_15037231/article/details/78158553 4.1 @Order Spring 4.2 利用@Order控制配置类的加载 ...
- 1.2 Use Cases中 Metrics官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Metrics 指标 Kafka is often used for operati ...
- React render return 空行问题
Uncaught Invariant Violation: App.render(): A valid React element (or null) must be returned. You ma ...