-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support an array of nodes in
contain
- Loading branch information
Showing
4 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import reactElementToJSXString from 'react-element-to-jsx-string' | ||
|
||
function reactArrayToJSXString (nodes) { | ||
let jsxString = '[' | ||
nodes.forEach((node, idx) => { | ||
jsxString += `\n ${reactElementToJSXString(node)}` | ||
if (idx < nodes.length - 1) { | ||
jsxString += ',' | ||
} | ||
}) | ||
return `${jsxString}\n]` | ||
} | ||
|
||
export default function reactNodeToString (node) { | ||
if (Array.isArray(node)) { | ||
return reactArrayToJSXString(node) | ||
} else { | ||
return reactElementToJSXString(node) | ||
} | ||
} |
This file contains 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