Guest User

Untitled

a guest
May 27th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. input: ["componentA", "componentB", "componentC"]
  2.  
  3. output:
  4. <ComponentA />
  5. <ComponentB />
  6. <ComponentC />
  7.  
  8. function renderElements(keys) {
  9. const components = {
  10. componentA: ComponentA,
  11. componentB: ComponentB,
  12. componentC: ComponentC,
  13. };
  14.  
  15. const componentsToRender = keys.map(key => components[key]);
  16.  
  17. return (
  18. <div>
  19. {componentsToRender}
  20. </div>
  21. );
  22. }
  23.  
  24. render() {
  25. const input = [ComponentA, ComponentB, ComponentC] // references to components
  26. return (
  27. <div>
  28. {input.map((comp, i) => React.createElement(comp, { key: i})}
  29. </div>
  30. );
  31. }
  32.  
  33. render()
  34. {
  35. const input=["ComponentA", "ComponentB", "ComponentC"]
  36.  
  37. return(
  38. <div>
  39. {
  40. input.map((comp,i)=>){
  41. return <{comp} key={i} />
  42. }
  43. }
  44. </div>
  45.  
  46. )
  47. }
Add Comment
Please, Sign In to add comment