我有一个react组件,它在挂载时接受dom引用(我知道这是一个边缘情况)。我想知道是否有必要将托管dom的属性设置为null
。或者react会处理它吗?
componentDidMount() {
this.elm = document.getElementById('foo')
}
componentWillUnmount(){
this.elm = null
}
发布于 2017-12-19 10:11:57
通过react文档,您只需清除全局元素,如使计时器无效、取消网络请求或清除在componentDidMount()中创建的任何订阅。
在卸载周期中,引用将随组件一起销毁。
https://reactjs.org/docs/react-component.html#componentwillunmount
https://stackoverflow.com/questions/47884059
复制相似问题