I am trying to implement react big calendar however I am having an issue with adding an event and using set state to update the event.I created a my calendar component then use the handle select function to take the new event and set the state but im not sure how I can set the state correctly. The documentation for set state uses render but I don't use render to display the calendar. Im not sure where I would need the constructor method or what I might be missing.
the current error is
TypeError: Cannot read property 'setState' of undefined
import React, { useState } from "react";
import "react-big-calendar/lib/css/react-big-calendar.css";
import Navigation from "../components/Navigation";
import events from "./events";
import { Calendar, momentLocalizer } from "react-big-calendar";
import moment from "moment";
const localizer = momentLocalizer(moment);
const handleSelect = ({ start, end }) => {
const title = window.prompt("New Event name");
alert("title " + title);
if (title) {
this.setState({
events: [
this.state.events,
{
start,
end,
title,
},
],
});
console.log(events);
}
};
const MyCalendar = (props) => (
<div>
<Navigation />
<Calendar
selectable
localizer={localizer}
events={events}
popup
startAccessor="start"
endAccessor="end"
style={{ height: 700 }}
onSelectSlot={handleSelect}
/>
</div>
);
export default MyCalendar;