Whenever it hits the point where an aircraft gets off of the map, and setState becomes false, it causes the setstate array filter to activate. This is causing many, if not all of the objects in the array to be removed from the screen / list on the right
const [location, setLocation] = useState(flightData.coordinate);
const [currentState, setState] = useState(true);
useEffect(() => {
if(currentState === false) {
setFlight(flights.filter(item => item.flightId !== flightData?.flightId));
}
const interval = setInterval(() => {
setLocation({...location, x: (location.x+(1*Math.cos(Math.PI/180*flightData?.heading))), y: location.y+(1*Math.sin(Math.PI/180*flightData?.heading))});
if (location.x < -5 || location.y < 0 || location.x > 105 || location.y > 150) {
setState(false);
}
}, 1000);
return() => clearInterval(interval);
}, [location, flightData.heading, flights]);
return(
<AircraftWrapper
data-testid="aircraft"
style={{left: `${getXPosition(location?.x)}`, top: `${getYPosition(location?.y)}`}}
heading={flightData?.heading+85}
/>
)
}```
flightData is the specific data for each flight being passed down.
flights is the total array of all of the flights being passed down in order to remove the specific flight from the array once it hits a state of false.
setFlight is the setState function from where flights is initialized being passed down in order to manipulate the total flights array.
The error I am seeing is that when the setFlight filter goes off, if the flight has the an index lower than other flights it is removing all flights after it. If it is at the end of the array, it is only removing itself.
If it