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的更多相关文章

  1. react recompose

    避免写嵌套 import { compose } from "recompose"; function Message(props) { const { classes } = p ...

  2. [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 ...

  3. [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 ...

  4. SVM与LR的区别以及SVM的优缺点

    对于异常数据,SVM比LR更好 SVM的优缺点: 优点:1.提供非常精确的分类器 2.更少的过拟合(因为有L2正则化项0.5||w||2),对噪声数据更加鲁棒(因为损失函数的原因) 缺点:1.SVM是 ...

  5. ML 激励函数 Activation Function (整理)

    本文为内容整理,原文请看url链接,感谢几位博主知识来源 一.什么是激励函数 激励函数一般用于神经网络的层与层之间,上一层的输出通过激励函数的转换之后输入到下一层中.神经网络模型是非线性的,如果没有使 ...

  6. [Converge] Training Neural Networks

    CS231n Winter 2016: Lecture 5: Neural Networks Part 2 CS231n Winter 2016: Lecture 6: Neural Networks ...

  7. react 使用的小建议

    使用pureRender,setState和Immutable.js来操作state Immutable 中文意思不可变. 不能直接修改state的值,要用setState 和Immutable re ...

  8. Vue基础:子组件抽取与父子组件通信

    在工作中承担一部分前端工作,主要使用Vue + Element UI. 随着版本迭代,需求增加,页面往往变得更加臃肿,不易维护.学习子组件的封装和抽取,能更好适应需求. 为什么需要子组件 可复用 将重 ...

  9. [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 ...

随机推荐

  1. Apache-DBUtils包对数据库的操作

    •commons-dbutils 是 Apache 组织提供的一个开源 JDBC工具类库,它是对JDBC的简单封装.学习成本极低.而且使用dbutils能极大简化jdbc编码的工作量,同一时候也不会影 ...

  2. 【UML】UML在软件开发各个阶段的应用

    一.UML5个互联视图 UML中经常使用5个互联的视图来描写叙述系统的体系结构. 如图 (1)用例视图(Use-case View) 由专门描写叙述可被终于用户.分析人员.測试人员看到的系统行为的用例 ...

  3. system.setting-全局变量数据监听

    今天在setting里添加了一个新的变量,想要实现对这个变量的监听.现在记录下方法 首先就是明白一点,我们在system.setting里添加的变量,都会被保存在data/data/com.andro ...

  4. C#截取中英文混合字符串分行显示

    private int GetStrByteLength(string str) { return System.Text.Encoding.Default.GetByteCount(str); } ...

  5. Spring学习总结(6)——Spring之核心容器bean

    一.Bean的基础知识 1.在xml配置文件中,bean的标识(id 和 name) id:指定在benafactory中管理该bean的唯一的标识.name可用来唯一标识bean 或给bean起别名 ...

  6. unity3d 改动gui label颜色,定义颜色需除以256

    GUIStyle titleStyle2 = new GUIStyle(); titleStyle2.fontSize = 20; titleStyle2.normal.textColor = new ...

  7. Java exception handling best practices--转载

    原文地址:http://howtodoinjava.com/2013/04/04/java-exception-handling-best-practices/ This post is anothe ...

  8. 1.12 Python基础知识 - 序列:字符串

    字符串是一个有序的字符集合,即字符序列.Pythpn内置数据类型str,用于字符串处理,使用单引号或双引号括起来的字符,就是字符常量,Python解释器会自动创建str型对象实例. 字符串的定义: 1 ...

  9. 谈谈Command对象与数据检索

    摘要 到目前为止,我相信大家对于ADO.NET如何与外部数据源建立连接以及如何提高连接性能等相关知识已经牢固于心了.连接对象作为ADO.NET的主力先锋,为用户与数据库交互搭建了扎实的桥梁.它的一生是 ...

  10. datetime小练习

    题目: 1.计算你的生日比如近30年来(1990-2019),每年的生日是星期几,统计一下星期几出现的次数比较多2,生日提醒,距离生日还有几天 # !/usr/bin/env python # -*- ...