This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-06-19
Channels
- # beginners (50)
- # boot (82)
- # cider (42)
- # clojure (206)
- # clojure-india (1)
- # clojure-nl (2)
- # clojure-poland (2)
- # clojure-russia (1)
- # clojure-uk (6)
- # clojurescript (223)
- # code-reviews (17)
- # core-typed (3)
- # datomic (7)
- # dunaj (3)
- # editors (2)
- # instaparse (3)
- # jobs (1)
- # ldnclj (37)
- # overtone (3)
- # reactive (1)
- # reading-clojure (1)
- # reagent (24)
- # remote-jobs (1)
Hi i have a question about reagent and children
If I create a component like this:
(defn aui-page-panel
[name]
(let [this (reagent/current-component)]
[:div.aui-page-panel
[:div.aui-page-panel-inner
[:section.aui-page-panel-content
(reagent/children this)]]]))
I can all it like this `[aui-page-panel "str" [:div "first"] [:div "second"]]
I can call*
[aui-page-panel "str" [:div "first"] [:div "second"]]
but when i remove the name argument like this:
`
(defn aui-page-panel
[]
(let [this (reagent/current-component)]
[:div.aui-page-panel
[:div.aui-page-panel-inner
[:section.aui-page-panel-content
(reagent/children this)]]]))
(defn aui-page-panel
[]
(let [this (reagent/current-component)]
[:div.aui-page-panel
[:div.aui-page-panel-inner
[:section.aui-page-panel-content
(reagent/children this)]]]))
I cannot call it anymore with children and it expects 3 arguments
Any ideas why?
@mitchelkuijpers: Hmm. I've never tried these sort of hyjinks. I'm a bit worried to see them. What are you trying to do?
Simply trying to make a component with children
Maybe I am doing it horribly wrong
Would something like this work (ignoring some divs):
(defn aui-page-panel
[name & args]
(into [:div name] (map #(vector :div %) args))) ;; results in [:div name [:div "first"] [:div "second"]]
;; used like this
[aui-page-panel "name" "first" "second"]
Note that I'm NOT passing in full child components, but rather the strings to be used in building the child components
Aha I actually want to pass some children components
but maybe I should just pass one child component
and then just do
[:div [child-component]]
In that case, I would have thought it was as simple as this (untested):
(defn aui-page-panel
[name child1 child2]
[:div name child1 child2])
;; used like this
[aui-page-panel "hello" [:div "first"] [:div "second"]]
Aha I wanted a variable amount of children
But I guess I was making it too hard for myself 😛
Variable number of children. Something like this (untested)?
(defn aui-page-panel
[name & children]
[:div name children]) ;; perhaps needs to be: (into [:div name] children)
;; used like this
[aui-page-panel "hello" [:div "first"] [:div "second"] [:div "third"]]
@mikethompson: the into works like charm 😄