Created
December 17, 2018 11:27
-
-
Save rajeshpillai/2529076dd958d75f77480e8909f01ebf to your computer and use it in GitHub Desktop.
createElement - Version - 1
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
| const TinyReact = (function () { | |
| function createElement(type, attributes = {}, ...children) { | |
| const childElements = [].concat(...children).map( | |
| child => | |
| child instanceof Object | |
| ? child | |
| : createElement("text", { | |
| textContent: child | |
| }) | |
| ); | |
| return { | |
| type, | |
| children: childElements, | |
| props: Object.assign({ children: childElements }, attributes) | |
| } | |
| } | |
| return { | |
| createElement | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment