I was working on this react application and after adding a new component DishDetail to my existing component Menu, somehow the super(props) stopped working and it is now showing a strikethrough and when i start my react app in yarn, it shows error that props are not passed.
Menu Component
import React, { Component } from 'react'
import DishDetail from './DishdetailComponent'
import { Card, CardImg, CardImgOverlay, CardText, CardBody,
CardTitle } from 'reactstrap';
class Menu extends Component {
constructor(props) {
super();
console.log(props)
this.state = {
selectedDish: null
}
}
onDishSelect(dish) {
this.setState({ selectedDish: dish});
}
renderDish(dish) {
if (dish != null)
return(
<Card>
<CardImg top src={dish.image} alt={dish.name} />
<CardBody>
<CardTitle>{dish.name}</CardTitle>
<CardText>{dish.description}</CardText>
</CardBody>
</Card>
);
else
return(
<div></div>
);
}
render() {
const menu = this.props.dishes.map((dish) => {
return (
<div className="col-12 col-md-5 m-1">
<Card key={dish.id}
onClick={() => this.onDishSelect(dish)}>
<CardImg width="100%" src={dish.image} alt={dish.name} />
<CardImgOverlay>
<CardTitle>{dish.name}</CardTitle>
</CardImgOverlay>
</Card>
</div>
);
});
return (
<div className="container">
<div className="row">
{menu}
</div>
<DishDetail dish={this.state.selectedDish} />
</div>
);
}
}
export default Menu;
Prev: I am not able to get the problem because there is no error detected in my visual studio code apart from the super being strikethrough so please help me out in understanding where the error is and what went wrong?
Updated code: Changed super(props) to super() since react version August 2020 no longer supports that
**Updated part: ** I have updated my code but it's showing Cannot read property 'map' of undefined error in const menu = this.props.dishes.map((dish) =>
of the Menu Component which I am unable to trace.