I represent a React component SettingsTabin a shell TeamView. Its API looks something like this:
SettingsTab
TeamView
class TeamView { constructor() { this.el = document.createElement('div'); } render() { ReactDOM.render(<SettingsTab/>, this.el); return this; } remove() { this.el.remove(); } }
used something like
// to present the team view const teamView = new TeamView(); document.body.appendChild(teamView.render().el); // to remove the team view teamView.remove();
And what interests me, should I TeamView#removecall ReactDOM. unmountComponentAtNode(this.el)before the callthis.el.remove() ?
TeamView#remove
ReactDOM. unmountComponentAtNode(this.el)
this.el.remove()
The examples that I can find on the Internet seem unmountComponentAtNodeto only need to be called if the container remains in the DOM; and a new example of portals just removes the container without calling unmountComponentAtNode.
unmountComponentAtNode
But I'm not sure this is special, because it uses the portal, and this post makes it look as always a good practice to call unmountComponentAtNode.
, unmountComponentAtNode(), , , .
unmountComponentAtNode()
- componentDidMount, . , window ( React), Redux, setInterval .. , componentWillUnmount.
componentDidMount
window
setInterval
componentWillUnmount
, DOM, unmountComponentAtNode, React , . componentWillUnmount , .
, , node. , , , (, , , ) componentDidMount.
this.el.remove(), unmountComponentAtNode(this.el), unmountComponentAtNode , remove .
unmountComponentAtNode(this.el)
remove
, , div, click:
var tap = document.querySelector('.tap'); var other = document.querySelector('.other'); tap.addEventListener('click', function(e) { console.log(tap.getAttribute('data-name') + ' has been clicked'); tap.remove(); }); other.addEventListener('click', function(e) { tap.click(); });
<div class="tap" data-name="tap">First Click me to remove me</div> <div class="other">Then Click me </div>
# response-internals :
, , @jiangangxiong : ,
we only need a removecontainer to have component event handlers and garbage collection, no need to call unmountComponentAtNode.
Source: https://habr.com/ru/post/1686600/More articles:perform operation opposite pandas ffill - pythonOne F # 4.1 compiler includes targetPlatform netstandard, the other non-f #Replicate a string from a dataset n times in Apache Spark using Java - javaHow to avoid using deadly function 30,000 times in list comprehension? - pythonReplication Spark Row N-times - scalaConditional non-join - rHow to configure WebStorm to debug Polymer - webstormDifference between min_samples_split and min_samples_leaf in sklearn DecisionTreeClassifier - pythonHanging line of text - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1686605/how-to-restrict-shell-options-to-a-function-using-local&usg=ALkJrhjZk-0DigGPACnPouVp1dB_UN0I5wAll Articles