I am trying to map over one of the two arrays from my imported js file ProductInformation.js.
This is in my main component class <ProductSquare arrayId = {door}/>
I have also tried <ProductSquare arrayId = {['door']}/>
What I am trying to do is only map the array (out of the two) which matches the panelId prop variable.
I get an error of TypeError: Cannot read property 'map' of undefined
export const door = [
{
id: 1,
productSquareId: 'door',
productImage: require('./door.png'),
companyImage: require('./logo.png'),
price: '$55.99',
},
{
id: 2,
productSquareId: 'door',
productImage: require('./door.png'),
companyImage: require('./logo.png'),
price: '$55.99',
},
]
export const lighting = [
{
id: 1,
productSquareId: 'lighting',
productImage: require('./lighting.png'),
companyImage: require('./logo.png'),
price: '$55.99',
}
import React, { Component } from 'react';
import './ProductSquare.css';
import './grid-container.css'
import {door, lighting} from './ProductInformation.js';
class ProductSquare extends Component {
constructor(props)
{
super(props)
this.state = {
};
}
PopulateProductSquares()
{
const ProductSquares = this.props.arrayId.map((product, i) =>
<div className = "ProductSquare">
<img className = "MainImage" src ={this.props.arrayId[i].productImage} alt = "test"/>
<img className = "CompanyImage" src ={this.props.arrayId[i].companyImage} alt = "test"/>
<button className = "AddButton">
Add
</button>
<button className = "InfoButton">
Info
</button>
</div>
)
return (
ProductSquares
)
}
render() {
return (
this.PopulateProductSquares()
)
}
}
export default ProductSquare;