I'm trying to use react-bootstrap mapping for my component but I get this error
Cannot destructure property 'Title' of 'fac' as it is undefined.
I think something is wrong when I try to destruct the props but I don't know which part should I fix and how to fix it. Does anyone know how to solve this problem ? Thanks in advance
Here's my code:
const facsInfo = [
{
Id: "1",
Title: "De'Spa",
Description: "dasda",
upperleftimg:"./Images/photo1.png",
upperrightimg:"./Images/photo2.png",
bottomleftimg:"",
bottomrightimg:"",
},
{
Id: "2",
Title: "De'Resto",
Description: "dsada",
upperleftimg:"./Images/photo3.png",
upperrightimg:"./Images/photo4.png",
bottomleftimg:"dasdas",
bottomrightimg:"",
},
]
const Facilities = () => {
const [currentId, setCurrentId] = useState();
useEffect(() => {
console.log(currentId);
}, [currentId]);
const showSelectedFact = () => {
var fac = facsInfo.filter((x) => x.Id === currentId)[0];
const { Title, Description, Id } = fac;
return (
<div key={Id}>
<h1>{Title}</h1>
<h5>{Description}</h5>
</div>
);
};
return (
<>
<Container fluid>
<Row className="facsHeader">
<Col lg={12} >
<h1>Facilities</h1>
<hr style={{border:'2px solid', color:'#967A50', width:'21.2%'}}></hr>
</Col>
</Row>
</Container>
<Container fluid>
<Row className="facsbuttwrapper text-center">
<Col sm={4} lg={4}>
<button
value="1"
className="facsButton"
onClick={(e) => setCurrentId(e.target.value)}
>
De'Spa
</button>
</Col>
<Col sm={4} lg={4}>
<button
value="2"
className="facsButton"
onClick={(e) => setCurrentId(e.target.value)}
>
De'Resto
</button>
</Col>
</Row>
</Container>
<Container fluid>
<Row className="text-center">
<Col md={12} lg={12}>
{showSelectedFact()}
</Col>
</Row>
</Container>
<Container fluid>
<Row>
<Col md={12} lg={12}>
{facsInfo.map((show) => {
const { upperleftimg, upperrightimg, Id } = show;
return (
<div key={Id} className="FacilitiesImg">
<img src={upperleftimg} alt="Image 1"></img>
<img src={upperrightimg} alt="Image 2"></img>
</div>
);
})}
</Col>
</Row>
</Container>
<Container fluid>
<Row>
<Col md={12} lg={12}>
{facsInfo.map((show) =>{
const {bottomleftimg, bottomrightimg, Id} = show
return(
<div key={Id} className="FacilitiesImg">
<img src={bottomleftimg} alt="Image 1"></img>
<img src={bottomrightimg} alt="Image 2"></img>
</div>
)
})}
</Col>
</Row>
</Container>
</>
)
}
export default Facilities