Replies: 2 comments 6 replies
-
Not necessarily, you can use the // DOM tree before render:
// <div id="container">
// <div>bar</div>
// <div id="target">foo</div>
// </div>
import { render } from 'preact';
const Foo = () => <div id="target">BAR</div>;
render(
<Foo />,
document.getElementById('container'),
document.getElementById('target')
);
// After render:
// <div id="container">
// <div>bar</div>
// <div id="target">BAR</div>
// </div> As the docs say though, that's going away in v11, so you may want to use this instead (works with v10+). You'll still need to create the nodes you want to replace, but it gives a bit more control anyways. |
Beta Was this translation helpful? Give feedback.
5 replies
-
Also interested in something more official. The gist works great but the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I maintain a web extension that needs to inject multiple pieces of DOM across the page rather than a single monolithic
<App/>
My code often would look like:
How could I achieve that in Preact? This is the closest I get, I think:
The issue is that
render
exclusively appends, so how would I go about using .before/.after/.prepend? Must I create a wrapper viadocument.createElement
first?This gets unwieldy fast, especially considering having to deal with the positioning/sizing of the extra wrapper element outside Preact.
This is kind of discussed in #1718, but here I'm looking for alternative ways to do this altogether, like via single component + portals. Maybe someone has had the same issue.
Beta Was this translation helpful? Give feedback.
All reactions