Last active
August 29, 2015 14:25
-
-
Save fubhy/864c47f3c0c6b28fdb75 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react/addons'; | |
import isArray from 'lodash/lang/isArray'; | |
import isObject from 'lodash/lang/isObject'; | |
import isFunction from 'lodash/lang/isFunction'; | |
// @todo Remove this once React 0.14 lands (parent based contexts). | |
export default function renderChildren() { | |
const { children, ...props } = this.props; | |
if (isFunction(children)) { | |
return children(props); | |
} | |
if (isArray(children)) { | |
return ( | |
<span>{React.Children.map(children, (child) => | |
React.addons.cloneWithProps(child) | |
)}</span> | |
); | |
} | |
if (isObject(children)) { | |
return React.addons.cloneWithProps(children); | |
} | |
return null; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment