React auto render
This file contains 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