Question: Rendering (inserting) before instead of appending
See original GitHub issueMaybe I’ve missed something. If render
is the proper way to generate code with Preact, I can’t seem to figure out the proper way to generate and insert code out-of-order. What I mean: render
appends.
For example:
render(<div>Post 1: Hello World</div>, document.body);
render(<div>Post 2: Blah Blah</div>, document.body);
Which outputs:
<div>Post 1: Hello World</div>
<div>Post 2: Blah Blah</div>
I want this instead:
<div>Post 2: Blah Blah</div>
<div>Post 1: Hello World</div>
Other than the obvious (switching the order), or inserting proxy elements that I target instead, what should I be doing in the 2nd line so it goes before the 1st element; Or specifically, so it inserts at the top of document.body
instead of the bottom?
Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Reactjs : Append instead of replacing with render method
that should work fine. but i would append it before rendering. · Can you explain your situation where you would want to do...
Read more >RTE Inserting/Rendering Link Appending Text
I am looking for the best way to append to the text of a RTE media link (PDF file type). Either on the...
Read more >How to Render in SketchUp (Answers to the 3 ... - YouTube
Want to learn photorealistic rendering ? This video answers the 3 questions everyone asks when struggling to get started.
Read more >Node.appendChild() - Web APIs - MDN Web Docs
cloneNode() method can be used to make a copy of the node before appending it under the new parent. Copies made with cloneNode...
Read more >Custom Render of Survey Elements - SurveyJS
Custom Render of Survey Elements | JS Survey and Form Library Example for React. ... Show Preview before complete ... Lazy questions rendering....
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
You can definitely re-render using
render()
, just you lose a lot of the benefits of component-based design. It’s also mildly confusing because there isrender()
(import { render } from 'preact'
) and there is also arender()
method on components.Here’s a little more fully-featured example continuing from above:
One thing worth noting: React/preact/etc actually simplify this kind of UI nicely, but it takes a little while to get used to the different way of doing things. Whereas with jquery/etc you might have to know “I want to insert new posts above existing posts”, with this component model, you only have to tell it how to render all posts (whether they are new or old). This way, determining whether new posts get injected first or last is simply a matter of choosing where to put them in an Array.
Happy to help 😃 Hopefully I’ll have some time to put better documentation together - I’d like to do some tutorials and such, perhaps on EggHead.io.