How to destroy root Preact node?
See original GitHub issueI want to destroy the root Preact DOM node. I initially render my component as follows:
import { h, render } from 'preact';
import App from "./components/App";
render(<App />, document.querySelector("#app");
How do I destroy App
? Do I simply unmount the #app
DOM node, or does Preact offer a method similar to React’s unmountComponentAtNode()
method?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to destroy root Preact node? - Stack Overflow
I want to destroy the root Preact DOM node. I initially render my component as follows: import { h, render } from 'preact';...
Read more >How to destroy root Preact node? · Issue #1151 - GitHub
To destory your app properly you can render null or '' (empty string) into your container and set the third parameter merge to...
Read more >API Reference | Preact
If you've already pre-rendered or server-side-rendered your application to HTML, Preact can bypass most rendering work when loading in the browser. This can...
Read more >[Solved]-How to destroy root Preact node?-Reactjs
Excerpt from compat for Preact X function unmountComponentAtNode(container) { if (container._prevVNode!=null) { render(null, container); return true; } ...
Read more >Preact-cli NPM
You can disable default: true flags by prefixing them with --no-<option> ; for example, --no-sw , --no-esm , and --no-inline-css . $ preact...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To destory your app properly you can render
null
or''
(empty string) into your container and set the third parametermerge
to your apps root element. Preact will then clean up the dom (okay it will leave an emptyTextNode
).Example:
Here the example: https://jsfiddle.net/8pcfntvz/4/
@cattermo It’s correct that render doesn’t return anything, but it did in older Preact versions during the 8.x release line. In current Preact versions (>= 10) the third argument can and should be omitted. We’re planning to drop it in the next major version.
To destroy a root node in current Preact versions (>= 10) calling
does the job.