Skip to content

Instantly share code, notes, and snippets.

@fubhy
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fubhy/864c47f3c0c6b28fdb75 to your computer and use it in GitHub Desktop.
Save fubhy/864c47f3c0c6b28fdb75 to your computer and use it in GitHub Desktop.
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