This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-30
Channels
- # announcements (41)
- # aws (2)
- # aws-lambda (1)
- # babashka (51)
- # babashka-sci-dev (15)
- # beginners (56)
- # calva (15)
- # cider (8)
- # clojars (6)
- # clojure (107)
- # clojure-dev (6)
- # clojure-europe (33)
- # clojure-france (3)
- # clojure-nl (4)
- # clojure-sg (2)
- # clojure-uk (8)
- # clojurescript (16)
- # cursive (11)
- # data-oriented-programming (1)
- # datomic (4)
- # events (11)
- # fulcro (15)
- # graphql (6)
- # helix (17)
- # holy-lambda (1)
- # improve-getting-started (14)
- # integrant (39)
- # jobs (14)
- # lsp (36)
- # malli (3)
- # nrepl (8)
- # off-topic (26)
- # other-languages (1)
- # polylith (21)
- # portal (7)
- # practicalli (17)
- # re-frame (7)
- # react (4)
- # reitit (1)
- # remote-jobs (6)
- # sci (1)
- # shadow-cljs (45)
- # spacemacs (12)
- # tools-deps (5)
- # xtdb (26)
Is there a way to render a sequence of components? I would expect this to work but it doesn’t
(defnc pages
[]
($ Routes
(for [page-props navbar-pages]
($ Route page-props))
($ Route {:path "*" :element (d/h1 "Page not found")})))
I guess this works, but let me know if theres a better way
(def route (helix/factory Route))
(defnc pages
[]
($ Routes
(for [page-props navbar-pages]
(route page-props))
($ Route {:path "*" :element (d/h1 "Page not found")})))
@alex395 when using $
, you should pass dynamic props in via the :&
prop. like ($ Route {:& page-props})
. see https://github.com/lilactown/helix/blob/master/docs/creating-elements.md#dynamic-props
another issue, hopefully also a common easy to fix one 😛 I have a custom defnc macro:
(ns lib.helix
#?(:clj (:require [helix.core :as helix]))
#?(:cljs (:require-macros [lib.helix])))
#?(:clj
(defmacro defnc [type params & body]
(let [[docstring params body] (if (string? params)
[params (first body) (rest body)]
[nil params body])
opts? (map? (first body)) ;; whether an opts map was passed in
opts (if opts?
(first body)
{})
body (if opts?
(rest body)
body)
;; feature flags to enable by default
default-opts {:helix/features {:fast-refresh true
:define-factory true
:check-invalid-hooks-usage true}}]
`(helix.core/defnc ~type ~@(when docstring [docstring]) ~params
;; we use `merge` here to allow individual consumers to override feature
;; flags in special cases
~(merge default-opts opts)
~@body))))
But when I use it, I can’t access props that are passed to the components. Heres a minimal example:
(ns some.ns
(:require [helix.core :as helix :refer [$]]
[lib.helix :refer [defnc]]
[helix.dom :as d]))
(defnc foo
[{:keys [bar]}]
(d/p bar))
(defnc view
[]
($ foo {:bar 1}))
When using my defnc, I see nothing. Inspecting the params of foo tells me that the {:bar 1}
map has been put into :children somehow
When using helix/defnc, it works as expectedMy defnc is basically copied straight from the helix docs and i think it should be doing the right thing