Skip to content

Instantly share code, notes, and snippets.

@juice49
Last active June 14, 2018 11:33
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 juice49/6775e0b3b2b85276133db34b99241ef3 to your computer and use it in GitHub Desktop.
Save juice49/6775e0b3b2b85276133db34b99241ef3 to your computer and use it in GitHub Desktop.
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