Last active
January 24, 2021 23:49
-
-
Save derekahn/069b83e5157eb2c4e0d47f751fb2c257 to your computer and use it in GitHub Desktop.
Iterating over an array of react components
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 { Component } from 'react'; | |
import Foo from 'components/Foo'; | |
import Bar from 'components/Bar'; | |
import Baz from 'components/Baz'; | |
class Container extends Component { | |
render() { | |
const components = [ | |
Foo, | |
Bar, | |
Baz | |
]; | |
return ( | |
<div> | |
{components.map((component, i) => | |
<div key={`component-${i}`> | |
{ React.createElement(component, { props: this.props }) } | |
</div> | |
)} | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment