问题
I am trying to fetch data from json file in firebase. I get this error before the app loads sometimes. The App still works.
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.
Kindly help me to fix this.
Here is my code :
const [dataSource, setData] = useState([]);
useEffect(() => {
fetch("https://jsonurlcomeshere/banners.json")
.then((response) => response.json())
.then((responseJson) => {
setData(responseJson);
})
.catch((error) => {
console.error(error);
});
}, []);
来源:https://stackoverflow.com/questions/65162525/while-fetching-data-from-json-cant-perform-a-react-state-update-on-an-unmounted