Greetings to everyone,
I have really no experience in working with class components as I have been using the normal functional easy ones but recently started a project that requires the class component,
I have the following state variable -
this.state = {
current: "City X"
};
Now in the methods for this class, I have a function -
codeAddress(geocoder) {
var marker;
var data = this.state.data;
marker.addListener("click", () => {
// On click - The state value of 'current' should update to another value.
this.setState({current: 'City Y'});
setTimeout(() => {
var pointA = new google.maps.LatLng(54.976713, -1.60728);
var request = {
origin: pointA,
destination: location,
travelMode: 'DRIVING'
};
directionsService.route(request, function (result, status) {
if (status == 'OK') {
directionsRenderer.setDirections(result);
}
});
}, 2000)
});
}
However this code gives an error that TypeError: Cannot read properties of undefined (reading 'setState')
I have binded all the functions in the constructor and tried a bunch of different techniques of updating the state value but haven't been able to figure it out exactly just yet.