原文链接:https://bobbyhadz.com/blog/react-cant-perform-react-state-update-on-unmounted-component[1]
作者:Borislav Hadzhiev[2]
正文从这开始~
总览
为了解决"Warning: Can't perform a React state update on an unmounted component"
,可以在你的useEffect
钩子中声明一个isMounted
布尔值,用来跟踪组件是否被安装。一个组件的状态只有在该组件被挂载时才会被更新。
import {useState, useEffect} from 'react';
const App = () => {
const [state, setState] = useState('');
useEffect(() => {
//