Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  108] [ 7]  / answers: 1 / hits: 17164  / 7 Years ago, tue, december 19, 2017, 12:00:00

I have a react component which take a dom reference when mounting (I know this is an edge case). I would like to know if it is necessary set to null the property which host the dom. Or does react take care of it?



componentDidMount() {
this.elm = document.getElementById('foo')
}

componentWillUnmount(){
this.elm = null
}

More From » reactjs

 Answers
1

By react documentation you need only to clean up globals elements such as invalidating timers, canceling network requests, or cleaning up any subscriptions that were created in componentDidMount().



A reference will be destroyed with the component on unmount cycle.



https://reactjs.org/docs/react-component.html#componentwillunmount


[#55640] Saturday, December 16, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adilene

Total Points: 395
Total Questions: 88
Total Answers: 109

Location: Indonesia
Member since Tue, Aug 3, 2021
3 Years ago
;