I have an array with objects including different coordinates such as:
bottomRow: 130.8201356
leftCol: 52.33386899
rightCol: 279.71340993
topRow: 48.9834268
what I need is to render squares based on this data. As many squares as there is different objects in the array.
I have tried this code with no success:
const FaceRecognition = ({imageUrl, box}) => {
console.log('recog',box)
return (
<div className='item-e center ma'>
<div className='absolute mt2 z-2'>
<img className='image br4 ma4 z-2' id='inputImage' src={imageUrl} alt=''/>
{ box.forEach(() => {
return (
<div className='bounding-box' style={{top: box.topRow, right: box.rightCol, bottom: box.bottomRow, left: box.leftCol}}>
</div>
)
}
)
}
</div>
</div>
);
}
how should I solve this so it takes all the objects and renders all the squares? So far I had to put [0] or any other array index next to box and it renders only that one object. but I need rendering all at once.
update:
I have tried box.map like this:
const FaceRecognition = ({imageUrl, box}) => {
console.log('recog',box)
return (
<div className='item-e center ma'>
<div className='absolute mt2 z-2'>
<img className='image br4 ma4 z-2' id='inputImage' src={imageUrl} alt=''/>
{ box.map(((topRow, rightCol, leftCol, bottomRow), idx) => {
<div key={idx} className='bounding-box' style={{top: box.topRow, right: box.rightCol, bottom: box.bottomRow, left: box.leftCol}}>
</div>
}
)
}
</div>
</div>
);
}
still no success, I get Invalid parenthesized assignment pattern now but can not figure out why
box.forEach()instead ofbox.map()? Array.forEach will always returnundefined, so its use case is more limited than map.