I have a fetch operation to receive coordinates into map markers. It works but it gives this error
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
at Screens/MapPage.js:71:45 in fetch.then.then$argument_0
The error line is in setLocations(result.data). The application works fine but I realized this error only occurs when I switch screens without waiting fetch completed. If I go back to home page without waiting setLocations is fetched. Is there better way to set the state into fetch result? I don't understand Where I am doing wrong?
fetch(baseUrl + "api/Product/GetAllProductLocalization", requestOptions)
.then(response => response.json())
.then((result) => {setLocations(result.data);} )
.catch(error => console.log('error', error));