Skip to content

Instantly share code, notes, and snippets.

@alanbsmith
Created May 15, 2016 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanbsmith/de82e9b747b32b4622a0fc7ffe5afa05 to your computer and use it in GitHub Desktop.
Save alanbsmith/de82e9b747b32b4622a0fc7ffe5afa05 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
// import SomeComponent from './components/SomeComponent';
// import AnotherComponent from './components/AnotherComponent';
const components = {
// Your components go here:
// 'SomeComponent': SomeComponent,
// 'AnotherComponent': AnotherComponent
}
const reactTargetDivs = document.getElementsByClassName('react-component-target');
let componentName, componentProps
Array.prototype.forEach.call(reactTargetDivs, function (targetDiv) {
componentName = targetDiv.getAttribute('data-react-class')
componentProps = JSON.parse(targetDiv.getAttribute('data-react-props'))
ReactDOM.render(
React.createElement(
components[componentName],
componentProps
),
targetDiv
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment