Hi I am building a frontend in react and I am rendering a List of places that I get from google maps api. I want each place to fire an action on onClick. If I don't pass any value it works, if I pass the id of the place that I get from props than onClick is fired when the list item is rendered leading to an error. Here is the list component
import {ListGroup} from "react-bootstrap";
import {useDispatch} from "react-redux";
import {selectedPlace} from "../../actions/searchActions";
const PlaceList=function (props) {
const dispatch=useDispatch()
const handleClick=function (id) {
console.log('ciao '+id)
}
return(
<ListGroup>
{props.places.map(item=>{
return (<ListGroup.Item variant="flush" onClick={handleClick(item['place_id'])}>{item['formatted_address']}</ListGroup.Item>)
})}
</ListGroup>
)
}
export default PlaceList
I want the onClick to be fired just when the list item is clicked. Any Idea on how to solve?