Created
May 15, 2018 16:53
-
-
Save benjasHu/48120663c4a77fc7db00bcf4088ea781 to your computer and use it in GitHub Desktop.
Render dynamically React children passing props
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
| /* | |
| You can use this function to dynamically render children in a Rect component, passing into parent's props. | |
| It checks if the children call is a function or a React element and render it with parent's props | |
| */ | |
| function renderChildren( children, props ) { | |
| return toString.call(children) == '[object Function]' ? children(props) : React.Children.map(children, child => React.cloneElement(child, props)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment