Hey guys I am trying to pass a command in a prop to child component from a parent. The thing is that after my button is clicked a state in parent component has to be changed for intended sidebar to open. I seem to not get it right with the .then() part at the end on the onClick function, as I get error: × Unhandled Rejection (TypeError): Cannot read property 'then' of undefined
CHILD COMPONENT:
return (
<div
className="results-item"
onClick={async () => {
let place_detail;
try {
const URL = `https://maps.googleapis.com/maps/api/place/details/json?place_id=${places.place_id}&fields=name,rating,formatted_phone_number&key=
MYAPIKEY`;
const response = await axios.get(URL);
console.log(response.data);
place_detail = response.data.results;
} catch (error) {
console.log(error.message);
}
this.setState({ place_detail }).then(this.props.sideBarOpen);
}}
>
<ResultsItem
name={places.name}
image={Thumbnail}
rating={places.rating}
rating_total={places.user_ratings_total}
/>
</div>
);
PARENT COMPONENT:
<Search sideBarOpen={() => setOpen(!open)} />