While fetching data from JSON Can't perform a React state update on an unmounted component

纵饮孤独 提交于 2021-01-29 20:00:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!