Skip to content

Instantly share code, notes, and snippets.

@rajeshpillai
Created December 17, 2018 11:27
Show Gist options
  • Save rajeshpillai/2529076dd958d75f77480e8909f01ebf to your computer and use it in GitHub Desktop.
Save rajeshpillai/2529076dd958d75f77480e8909f01ebf to your computer and use it in GitHub Desktop.

Revisions

  1. rajeshpillai created this gist Dec 17, 2018.
    21 changes: 21 additions & 0 deletions tiny-react-createElement-1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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
    }
    }());