This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-11
Channels
- # ai (2)
- # announcements (5)
- # babashka (16)
- # beginners (24)
- # calva (22)
- # clerk (2)
- # clj-yaml (4)
- # cljsrn (1)
- # clojure (15)
- # clojure-dev (7)
- # data-science (5)
- # datalevin (1)
- # emacs (21)
- # events (1)
- # hyperfiddle (33)
- # lsp (71)
- # membrane (1)
- # podcasts-discuss (1)
- # practicalli (11)
- # re-frame (17)
- # reagent (3)
- # sci (1)
- # shadow-cljs (47)
- # transit (1)
Hey all. I'm writing a browser extension for a web page that I don't control. There's some existing HTML into which I'd like to render a react component, and ideally I'd like to mix and match new react components with existing elements. Is this possible? So the page looks something like this
<div class="container">
<div class="header">...</div>
<div class="content">...</div>
</div>
And I want to do something like the following, once the page loads:
(let [ele (first (js/document.getElementsByClassName "container"))
header (first (.getElementsByClassName ele "header"))
content (first (.getElementsByClassName ele "content"))]
(rdom/render
[:div
header ; <- use the existing header somehow
[:p "Some new thing before the content"]
content] ; <- use the existing content somehow
ele))
Of course, this is not possible, because the references to header
and content
are references to real elements, not valid react children. Is there some clever way to accomplish this with refs? From what I can tell they only help in the reverse direction.