This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-22
Channels
- # aleph (20)
- # announcements (4)
- # babashka (72)
- # beginners (64)
- # biff (5)
- # calva (146)
- # cider (5)
- # clj-kondo (18)
- # clj-together (3)
- # cljsrn (28)
- # clojure (95)
- # clojure-berlin (2)
- # clojure-europe (34)
- # clojure-nl (2)
- # clojure-norway (3)
- # clojure-uk (3)
- # community-development (7)
- # conjure (1)
- # cursive (2)
- # data-science (12)
- # datalevin (13)
- # datomic (17)
- # events (2)
- # figwheel-main (5)
- # fulcro (7)
- # helix (8)
- # hyperfiddle (52)
- # jobs (1)
- # malli (14)
- # off-topic (32)
- # polylith (24)
- # remote-jobs (7)
- # scittle (3)
- # shadow-cljs (14)
- # slack-help (3)
- # spacemacs (3)
- # vim (2)
- # xtdb (6)
Hello quick question, I have the following sample:
;; works
($ "div" {:class "class-name"} "hello")
;; don't work
(defn style [] {:class "class-name"})
($ "div" (style) "hello")
I saw that the $
does some type checks on the args, what is the best approach to support this behavior currently? I was playing around https://github.com/kushidesign/kushi thought to test it with helix, but ended up having this problem.It throws the following:
Uncaught Error: Objects are not valid as a React child (found: object with keys {key, val, __hash, cljs$lang$protocol_mask$partition0$, cljs$lang$protocol_mask$partition1$}). If you meant to render a collection of children, use an array instead.
Strange, I'm definitely doing something wrong here, if I copy the definition of $
locally it works. oO
(defn $$
"Create a new React element from a valid React type.
Example:
($ MyComponent
\"child1\"
($ \"span\"
{:style {:color \"green\"}}
\"child2\" ))
"
[type & args]
(let [?p (first args)
?c (rest args)
native? (or (keyword? type)
(string? type)
(:native (meta type)))
type' (if (keyword? type)
(name type)
type)]
(println ?p (map? ?p))
(if (map? ?p)
(apply create-element
type'
(if native?
(impl.props/-dom-props ?p)
(impl.props/-props ?p))
?c)
(apply create-element
type'
nil
args))))
Just added a print for debug and
;; now works oO
($$ "div" (style) "hello")
You can read about it here https://github.com/lilactown/helix/blob/master/docs/creating-elements.md#dynamic-props
the definition you copied is of the CLJS function form, not the macro form. When you call ($ ,,,)
CLJS chooses the macro first. if you pass the $
as a value, like (apply $ ,,,)
then it will use the function that you copied, which does handle dynamic props but is slower.
Got it! Thanks for clarifying