2017-02-09 19 views
2

Например:Как создать элемент appendChild reagent?

(defn place-background [] 
     [:div {:class "pbackground" 
      :style {:height (:fullheight @app-state)}}]) 

    (reagent/render-appendChild [place-background] 
          (. js/document (getElementById "container"))) 

, потому что, если я использовать рендер-компонент будет заменить содержимое

ответ

2
(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"))) 
+0

Но если я хочу дублировать? 2 элемента в моем «приложении» .. например: (draw {: width "200px: height" 200px "}) (draw {: width" 200px: height "200px"}) –