例如:
(defn place-background []
[:div {:class "pbackground"
:style {:height (:fullheight @app-state)}}])
(reagent/render-appendChild [place-background]
(. js/document (getElementById "container")))
因为如果我使用render-component,它将替换内容
答案 0 :(得分:3)
(ns reagenttest.core
(:require [reagent.core :as r]))
(defn sample-comp []
[:div "hello there!"])
(defn appended-container [target]
(let [id "some-unique-id"
container (.getElementById js/document id)]
(if container
container
(.appendChild target (doto (.createElement js/document "div")
(-> (.setAttribute "id" id))))
)))
(r/render [sample-comp] (appended-container (.getElementById js/document "app")))