I have a component looks something like this:
<ImageComponent
image={this.props.data.image1}
/>
<ImageComponent
image={this.props.data.image2}
/>
<ImageComponent
image={this.props.data.image3}
/>
What I am trying to do is render this component which has multiple images in a dynamic order based on data that I have before hand.
[{
img: image1,
placementIndex: 2
},
{
img: image2,
placementIndex: 0
}
{
img: image3,
placementIndex: 1
}]
I dont think the way I have tried is very efficient
const imageComponentPlacement = [];
this.props.componentOrder.map((placement) => {
const componentToUse = (<ImageComponent
image={this.props.data[placement.img]}
/>);
imageComponentPlacement.splice(placement.placementIndex, 0, componentToUse);
}
return imageComponentPlacement.map((NewImagePlacement, index) =>
<div key={index}>
<NewImagePlacement />
</div>
);
This is how I have tried it, but cant seem to get it to work. I get an error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
Is pushing the component to the array an issue then trying to render the array? Not quite sure where to go from here. Thanks!