Skip to content

Instantly share code, notes, and snippets.

@juice49
Last active June 14, 2018 11:33
Embed
What would you like to do?
React auto render
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