React newbie here! I have an object cats which contains a list of lat long cords for cat locations. I am trying to pass the object down into the MapContainer component like so:
<MapContainer cats={cats} /></div>
MapContainer component:
export class MapContainer extends Component {
constructor(props) {
super(props);
this.state = {
cats: // this should come from the parent component
}
}
displayMarkers = () => {
return this.state.cats.map((cat, index) => {
return <Marker key={index} id={index} position={{
lat: cat.latitude,
lng: cat.longitude
}}
onClick={() => console.log("You clicked me!")} />
})
}
render() {
return (
<Fragment>
<Map
google={this.props.google}
zoom={8}
style={mapStyles}
initialCenter={{ lat: 47.444, lng: -122.176}}
>
{this.displayMarkers()}
</Map>
</Fragment>
);
}
}
How can I adjust my class component to take the cats object in?
this.props.cats.mapinstead ofthis.state.cats.mapin displayMarkers function?