I need to call cancelMethod
with params from Button onClick inside popover
. However I could not access this method. Can you explain is it possible to access. If yes how can I do it?
const popover = (
<Popover id="popover-basic">
<Popover.Title as="h3">Cancel reservation</Popover.Title>
<Popover.Content>
for <strong>canceling</strong> course. Click here:
<Button onClick={cancelMethod()} variant='danger'>Cancel</Button>
</Popover.Content>
</Popover>
);
const Event = ({event}) => (
<OverlayTrigger trigger="click" placement="top" overlay={popover}>
<Button
style={{background:"transparent", border:"none"}}
>{event.title} <br/> Lecture Room:{event.room}<br/> Teacher: {event.instructor}</Button>
</OverlayTrigger>
);
export default class NewCalendarView extends Component {
cancelMethod(id){
alert("Hello"+id);
}
componentDidMount() {
API.getLectures().then((res)=>{
console.log(res)
const cal=res.map((lec)=>{
let lecture= {
instructor: lec.teacherName,
room: lec.room,
title: lec.subject,
startDate : moment(lec.date+"T"+lec.hour).toDate(),
endDate: moment(lec.date+"T"+lec.hour+"-02:00").toDate()
}
return lecture;
})
this.setState({events:cal,loading:null,serverErr:null})
}).catch((err)=>{
this.setState({serverErr:true,loading:null})
})
}
constructor(props) {
super(props);
this.state = {
events: []
}
}
render() {
return (
<div style={{
flex: 1
}}>
{console.log(this.state.events)}
<Calendar
localizer={localizer}
events={this.state.events}
startAccessor='startDate'
endAccessor='endDate'
defaultView='week'
views={['month', 'week', 'day']}
culture='en'
components={{
event: Event
}}
/>
</div>
);
}
}