簡體   English   中英

警告:無法對未安裝的組件 React Native 執行 React 狀態更新

[英]Warning: Can't perform a React state update on an unmounted component React Native

我不知道為什么我面臨這個問題。 如果有人知道如何處理它,請幫助。 提前致謝

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 %s.%s, the componentWillUnmount method,
    in ToastContainer (at connectStyle.js:392)
    in Styled(ToastContainer) (at Root.js:16)
    in RCTView (at View.js:45)
    in View (at Root.js:14)
    in Root (at connectStyle.js:392)
    in Styled(Root) (at LoginScreen.js:93)
    in LoginScreen (at SceneView.js:9)
    in SceneView (at StackViewLayout.tsx:889)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.tsx:888)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.tsx:887)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:151)
    in AnimatedComponent (at StackViewCard.tsx:106)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:151)
    in AnimatedComponent (at screens.native.js:71)
    in Screen (at StackViewCard.tsx:93)
    in Card (at createPointerEventsContainer.tsx:95)
    in Container (at StackViewLayout.tsx:975)
- node_modules\react-native\Libraries\YellowBox\YellowBox.js:59:8 in error
- node_modules\expo\build\environment\muteWarnings.fx.js:27:24 in error
- ... 12 more stack frames from framework internals

首先,你應該像這樣用<Root>包裝你的應用程序組件

<Root> <App/> </Root>

如果你已經這樣做了,然后確保你是不是叫<Root>內的另一個<Root> 請參閱此鏈接

該錯誤意味着您正在嘗試更新當前未安裝的組件的狀態。

由於您沒有共享任何代碼,我只能猜測您正在執行一些異步任務(例如后端調用)並更新組件的狀態,但是當調用解決時,組件已經卸載。 查看錯誤,我認為您正在嘗試在 Toast 組件被解除后更改其狀態。


在卸載之前使用 componentWillUnmount 中止所有異步任務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM