-
-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix returned null in stateless function in react@0.14.x
- Loading branch information
Showing
1 changed file
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |