相关疑难解决方法(0)

如果删除组件的容器,是否需要调用`unmountComponentAtNode`?

SettingsTab在一个名为的包装器中呈现一个React组件TeamView.它的API看起来像

class TeamView {
  constructor() {
    this.el = document.createElement('div');
  }

  render() {
    ReactDOM.render(<SettingsTab/>, this.el);
    return this;
  }

  remove() {
    this.el.remove(); 
  }
}
Run Code Online (Sandbox Code Playgroud)

用过类似的东西

// to present the team view
const teamView = new TeamView();
document.body.appendChild(teamView.render().el);

// to remove the team view
teamView.remove();
Run Code Online (Sandbox Code Playgroud)

我想知道的是,在打电话之前应该TeamView#remove打电话ReactDOM. unmountComponentAtNode(this.el)this.el.remove()吗?

我可以在网络上找到的示例使得看起来unmountComponentAtNode只需要在容器将保留在DOM中时才需要调用它; 并且新的门户示例只是删除容器,而不调用unmountComponentAtNode.

但是,我不确定这是否特别,因为它正在使用门户网站,而且这篇帖子让人觉得打电话总是好的做法unmountComponentAtNode.

reactjs react-dom

11
推荐指数
1
解决办法
4981
查看次数

标签 统计

react-dom ×1

reactjs ×1