From 5b0dc7a26d53f594a2a0b561158d90170214b5ef Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 2 Aug 2016 14:05:35 +0800 Subject: [PATCH] Fix returned null in stateless function in react@0.14.x https://github.com/facebook/react/pull/5884 --- src/ExpandIcon.jsx | 47 +++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/ExpandIcon.jsx b/src/ExpandIcon.jsx index 16f8f041a..60b3b5e68 100644 --- a/src/ExpandIcon.jsx +++ b/src/ExpandIcon.jsx @@ -1,16 +1,33 @@ -import React from 'react'; +import React, { PropTypes } from 'react'; +import shallowequal from 'shallowequal'; -export default ({ expandable, prefixCls, onExpand, needIndentSpaced, expanded, record }) => { - if (expandable) { - const expandClassName = expanded ? 'expanded' : 'collapsed'; - return ( - onExpand(!expanded, record)} - /> - ); - } else if (needIndentSpaced) { - return ; - } - return null; -}; +const ExpandIcon = React.createClass({ + propTypes: { + record: PropTypes.object, + prefixCls: PropTypes.string, + expandable: PropTypes.any, + expanded: PropTypes.bool, + needIndentSpaced: PropTypes.bool, + onExpand: PropTypes.func, + }, + shouldComponentUpdate(nextProps) { + return !shallowequal(nextProps, this.props); + }, + render() { + const { expandable, prefixCls, onExpand, needIndentSpaced, expanded, record } = this.props; + if (expandable) { + const expandClassName = expanded ? 'expanded' : 'collapsed'; + return ( + onExpand(!expanded, record)} + /> + ); + } else if (needIndentSpaced) { + return ; + } + return null; + }, +}); + +export default ExpandIcon;