Skip to content

Commit

Permalink
Fix returned null in stateless function in react@0.14.x
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Aug 2, 2016
1 parent 5add82b commit 5b0dc7a
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/ExpandIcon.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<span
className={`${prefixCls}-expand-icon ${prefixCls}-${expandClassName}`}
onClick={() => onExpand(!expanded, record)}
/>
);
} else if (needIndentSpaced) {
return <span className={`${prefixCls}-expand-icon ${prefixCls}-spaced`} />;
}
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 (
<span
className={`${prefixCls}-expand-icon ${prefixCls}-${expandClassName}`}
onClick={() => onExpand(!expanded, record)}
/>
);
} else if (needIndentSpaced) {
return <span className={`${prefixCls}-expand-icon ${prefixCls}-spaced`} />;
}
return null;
},
});

export default ExpandIcon;

0 comments on commit 5b0dc7a

Please sign in to comment.