Skip to content

Instantly share code, notes, and snippets.

@derekahn
Last active January 24, 2021 23:49
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 derekahn/069b83e5157eb2c4e0d47f751fb2c257 to your computer and use it in GitHub Desktop.
Save derekahn/069b83e5157eb2c4e0d47f751fb2c257 to your computer and use it in GitHub Desktop.
Iterating over an array of react components
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