question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unmountComponentAtNode

See original GitHub issue

There seem to be no way to properly unmount components from domNode at the moment. Or maybe I am missing something?) Any plans to add unmountComponentAtNode method? Thanks =)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

13reactions
developitcommented, Feb 16, 2016

parent is the node you want to render into, root is the node that got rendered by your preact.render() call.

Here’s a JSFiddle example: https://jsfiddle.net/developit/6ycn8ptL/

I should also add that you can do this using a wrapper component that returns null:

const Nothing = () => null;

let root = render(<MyComponent />, document.body);

// un-render:
render(<Nothing />, document.body, root);
9reactions
developitcommented, Feb 16, 2016

For “unrendering”, I tend to do this:

render('', parent, root);

… but I agree that’s a bit of a hack. If the implementation of unmountComponentAtNode is small enough, I will absolutely try to add it to Preact itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactDOM – React
unmountComponentAtNode has been replaced with root.unmount() in React 18. See createRoot for more info. Remove a mounted React component from the DOM and...
Read more >
ReactJS unmountComponentAtNode() Method - GeeksforGeeks
In class-based components, the unmountComponentAtNode() method Remove a mounted React component from the DOM. Creating React Application:.
Read more >
reactjs - Is it necessary to call `unmountComponentAtNode` if ...
Yes, it is important to call unmountComponentAtNode() because if you don't do this, none of the components below in the tree will know...
Read more >
How to Unmount a ReactJS Node - Pluralsight
React has a top-level API called unmountComponentAtNode() that removes a component from a specific container.
Read more >
What is the purpose of unmountComponentAtNode method?
What is the purpose of unmountComponentAtNode method? ... This method is available from react-dom package and it removes a mounted React component from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found