Last active
June 14, 2018 11:33
-
-
Save juice49/6775e0b3b2b85276133db34b99241ef3 to your computer and use it in GitHub Desktop.
React auto render
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
import React from 'react' | |
import { render } from 'react-dom' | |
import Foo from './components/foo' | |
const components = { | |
foo: Foo | |
} | |
Object.keys(components) | |
.map(name => { | |
const Component = components[name] | |
const className = `.js-component-${name}` | |
const targets = document.querySelectorAll(className) | |
;[ ...targets ].forEach(target => { | |
render(<Component />, target) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment