Created
March 28, 2019 02:01
-
-
Save hnq90/074053fde47fec774bb4aea931aff6b1 to your computer and use it in GitHub Desktop.
renderNode.js
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'; | |
| const renderNode = (Component, content, defaultProps) => { | |
| if (content == null || content === false) { | |
| return null; | |
| } | |
| if (React.isValidElement(content)) { | |
| return content; | |
| } | |
| if (typeof content === 'function') { | |
| return content(); | |
| } | |
| // Just in case | |
| if (content === true) { | |
| return <Component {...defaultProps} />; | |
| } | |
| if (typeof content === 'string' || typeof content === 'number') { | |
| return <Component {...defaultProps}>{content}</Component>; | |
| } | |
| return <Component {...defaultProps} {...content} />; | |
| }; | |
| export default renderNode; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment