gpt4 book ai didi

javascript - componentWillUnmount 没有被调用

转载 作者:数据小太阳 更新时间:2023-10-29 05:49:35 27 4
gpt4 key购买 nike

我有一个主干应用程序,我试图在其中集成 React 组件。

React 组件使用以下代码安装: ReactDOM.render(
<WrappedComponent />, node
);
其中 node 是 DOM 模式。这样 React 生命周期事件(例如 componentWillMount 和 componentDidMount)就可以正常调用。

但是当通过 Backbone 路由进行路由时,并且 React 组件从 DOM 中移除时,不会调用 componentWillUnmount。

有什么解决办法吗?

最佳答案

componentWillUnmount 不会在容器节点被移除时自动调用。它只会被调用:

  1. 在顶层,当您调用 ReactDOM.unmountComponentAtNode
  2. 作为子组件,当父组件卸载时

关于javascript - componentWillUnmount 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34691303/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com