From 71fc0774c01cbb99a9805d3aa655625870e351ec Mon Sep 17 00:00:00 2001 From: Leon Shi Date: Tue, 7 Jun 2016 17:54:06 +0800 Subject: [PATCH] implement shouldComponentUpdate to make the re-render much faster for Checkbox --- components/checkbox/Group.jsx | 4 ++++ components/checkbox/index.jsx | 4 ++++ package.json | 1 + 3 files changed, 9 insertions(+) diff --git a/components/checkbox/Group.jsx b/components/checkbox/Group.jsx index 49089a261c..5ec570d40d 100644 --- a/components/checkbox/Group.jsx +++ b/components/checkbox/Group.jsx @@ -1,5 +1,6 @@ import React from 'react'; import Checkbox from './index'; +import PureRenderMixin from 'react-addons-pure-render-mixin'; export default class CheckboxGroup extends React.Component { static defaultProps = { @@ -30,6 +31,9 @@ export default class CheckboxGroup extends React.Component { }); } } + shouldComponentUpdate(...args) { + return PureRenderMixin.shouldComponentUpdate.apply(this, args); + } getOptions() { const { options } = this.props; return options.map(option => { diff --git a/components/checkbox/index.jsx b/components/checkbox/index.jsx index aa774a589f..9bca526e12 100644 --- a/components/checkbox/index.jsx +++ b/components/checkbox/index.jsx @@ -2,12 +2,16 @@ import RcCheckbox from 'rc-checkbox'; import React from 'react'; import CheckboxGroup from './Group'; import classNames from 'classnames'; +import PureRenderMixin from 'react-addons-pure-render-mixin'; export default class Checkbox extends React.Component { static Group = CheckboxGroup; static defaultProps = { prefixCls: 'ant-checkbox', } + shouldComponentUpdate(...args) { + return PureRenderMixin.shouldComponentUpdate.apply(this, args); + } render() { const { prefixCls, style, children, className, ...restProps } = this.props; const classString = classNames({ diff --git a/package.json b/package.json index e158df8259..f23cf36f6c 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "rc-upload": "~1.13.0", "rc-util": "~3.1.3", "react-slick": "~0.12.0", + "react-addons-pure-render-mixin": "~15.1.0", "warning": "~3.0.0" }, "devDependencies": {