Skip to content

Instantly share code, notes, and snippets.

@stuartpearman
Last active May 17, 2018 18:20
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 stuartpearman/60bc64291dfbea3e5be3d8bc30f5c49c to your computer and use it in GitHub Desktop.
Save stuartpearman/60bc64291dfbea3e5be3d8bc30f5c49c to your computer and use it in GitHub Desktop.
import React from 'react'
const Loader = () => {
// This is a plain 'ol javascript object, but it could easily
// be parsed JSON from an API
const componentList = [
{
name: 'Test',
content: 'I am some text',
props: {}
},
{
name: 'Test2',
content: 'I too am some text 2',
props: {}
}
]
// Ditch the JSX syntax to allow us to build the component
// dynamically
const components = componentList.map((component, i) =>
React.createElement(
// load in the component with require (this needs to be
// compiled using webpack or similar)
require(`components/${component.name}`),
{...component.props, key: i},
component.content
)
)
return <div>{components}</div>
}
export default Loader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment