Last active
May 17, 2018 18:20
-
-
Save stuartpearman/60bc64291dfbea3e5be3d8bc30f5c49c to your computer and use it in GitHub Desktop.
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' | |
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