2017-02-09 8 views
2

Zum Beispiel:Wie erstelle ich ein appendChild-Reagenzelement?

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

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

denn wenn ich es zu benutzen machen-Komponente wird den Inhalt

Antwort

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

Aber wenn ich duplizierende ersetzen? 2 Elemente in meiner "App" .. zum Beispiel: (ziehe {: width "200px: height" 200px "}) (ziehe {: width" 200px: height "200px"}) –