1 | import React from 'react';
|
2 | const renderNode = (Component, content, defaultProps = {}) => {
|
3 | if (content == null || content === false) {
|
4 | return null;
|
5 | }
|
6 | if (React.isValidElement(content)) {
|
7 | return content;
|
8 | }
|
9 | if (typeof content === 'function') {
|
10 | return content();
|
11 | }
|
12 |
|
13 | if (content === true) {
|
14 | return <Component {...defaultProps}/>;
|
15 | }
|
16 | if (typeof content === 'string') {
|
17 | if (content.length === 0) {
|
18 | return null;
|
19 | }
|
20 | return <Component {...defaultProps}>{content}</Component>;
|
21 | }
|
22 | if (typeof content === 'number') {
|
23 | return <Component {...defaultProps}>{content}</Component>;
|
24 | }
|
25 | return <Component {...defaultProps} {...content}/>;
|
26 | };
|
27 | export default renderNode;
|