React Native - 当“componentWillUnmount"时;会被叫? [英] React Native - When "componentWillUnmount" will be called?

查看:30
本文介绍了React Native - 当“componentWillUnmount"时;会被叫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Navigator 以便在页面之间导航.

I'm using the Navigator in order to navigate between pages.

Navigator.push() 方法被调用时,componentWillUnmount"方法未在我们导航的页面上调用.

When Navigator.push() method is called, the "componentWillUnmount" method isn't called on the page we're navigating from.

有点问题,因为我想从听众等那里退订

It's a little bit problematic because I want to unsubscribe from listeners, etc.

这是正常行为吗?什么时候真正调用了componentWillUnmount"?

Is it a normal behavior? When the "componentWillUnmount" is actually called?

推荐答案

Navigator 使用堆栈来管理路由.当你推送一个新页面时,当前页面不会卸载,如果你从新页面弹出到当前页面新页面 将卸载.而在其他场景中,如果根据isLoading等规则渲染某个子组件,当不再需要渲染时,也会调用componentWillUnmount方法.

Navigator uses stack to manager route. When you push a new page, current page wont unmount, if you pop from new page to the current page, the new page will unmount. And in other scene, if you render some child component based on some regulation like isLoading or other, the componentWillUnmount method will also be called when they no longer need to be rendered.

这篇关于React Native - 当“componentWillUnmount"时;会被叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆