Guest User

Untitled

a guest
May 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import React from 'react'
  2.  
  3. const Loader = () => {
  4. // This is a plain 'ol javascript object, but it could easily
  5. // be parsed JSON from an API
  6.  
  7. const componentList = [
  8. {
  9. name: 'Test',
  10. content: 'I am some text',
  11. props: {}
  12. },
  13. {
  14. name: 'Test2',
  15. content: 'I too am some text 2',
  16. props: {}
  17. }
  18. ]
  19.  
  20. // Ditch the JSX syntax to allow us to build the component
  21. // dynamically
  22.  
  23. const components = componentList.map((component, i) =>
  24. React.createElement(
  25. // load in the component with require (this needs to be
  26. // compiled using webpack or similar)
  27. require(`components/${component.name}`),
  28. {...component.props, key: i},
  29. component.content
  30. )
  31. )
  32.  
  33. return <div>{components}</div>
  34. }
  35.  
  36. export default Loader
Add Comment
Please, Sign In to add comment