How to ask a rerender without killing the virtual DOM
See original GitHub issueHey guys, i got a quick question, and i do not know if what i want is possible.
In my project i cannot use JSX for preact, so i use Preact API directly to createElement
(via h()
) and render
.
My problem is that i have to wipe entirely the preact root when i want to rerender, i do something like this :
// nested childs with changing props on runtime
const PreactComponent = Preact.h(
TranslatorProvider, // already a preact component
{
locale,
translations
},
Preact.h(
Component, // already a preact component
config
)
);
// HACK alike React.unmountComponentAtNode(container.body)
// https://github.com/developit/preact/issues/53
if (this.root) {
// wiping the dom to prevent duplicate
Preact.render('', container.body, this.root);
} else {
// TODO : rerender preact without killing the virtual DOM
}
// then totally rerender the component
this.root = Preact.render(PreactComponent, container.body);
What is the API to allow my code to know that the node is already loaded, and only update the props for it ? I cannot find it anywhere.
Thank for those who may help.
Notes:
- i use
"preact": "7.1.0"
and cannot move from it - My preact code is rendered into a local iframe, i don’t think it can be a problem, but still, it’s an information to consider
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to ask a rerender without killing the virtual DOM #1259
Hey guys, i got a quick question, and i do not know if what i want is possible. In my project i cannot...
Read more >Preventing react from rendering unchanged componets into ...
Improving ReactJS rendering performance. First off, don't spend time on this unless you see the need for it in your application.
Read more >How to Render Components Outside the Main ReactJS App
Lets take a look at the full code and then break it down: import React from 'react'; import { render } from 'react-dom';...
Read more >Virtual DOM, Reconciliation And Diffing Algorithm Explained ...
In simple words, virtual DOM is just a copy of the original DOM kept in the memory and synced with the real DOM...
Read more >The 2 Mistakes I did while using React State that I wish I never ...
If your state is holding a piece of UI that gets injected into the DOM, keeping track of the changes on that DOM...
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
Normally, you get the resulting root node in render. If you pass the same root node into the next render process, it should properly diff/update instead of replacing:
You basically did this already, but just passed an empty string to it, to remove it. You don’t need to do that, as long as you are passing the third parameter to
render
(which is calledmergeWith
, so it already hints at the purpose) you should be fine.