Skip to content

Instantly share code, notes, and snippets.

@alepeino
Created November 29, 2017 20:43
Show Gist options
  • Save alepeino/fee59d00eb1a7d4ceb4ca630b47bbb82 to your computer and use it in GitHub Desktop.
Save alepeino/fee59d00eb1a7d4ceb4ca630b47bbb82 to your computer and use it in GitHub Desktop.
// https://vuejs.org/v2/guide/components.html#DOM-Template-Parsing-Caveats
const originalRender = ReactDOM.render
const components = { }
function renderElement (e, i) {
return e.tagName
? React.createElement(
components[e.localName] || e.localName,
Array.from(e.attributes).reduce((r, n) => { r[n.localName] = eval(n.nodeValue); return r; }, { key: i }),
...renderChildNodes(e)
)
: e.textContent
}
function renderChildNodes (element) {
return Array.from(element.childNodes).map(renderElement)
}
ReactDOM.render = (component, domNode) => {
return domNode
? originalRender(component, domNode)
: (domNode = component) && originalRender(renderChildNodes(domNode), domNode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment