Can't perform a React state update on an unmounted component报错解决
Borislav Hadzhiev 人气:0总览
为了解决"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(() => { //
加载全部内容
- 猜你喜欢
- 用户评论