This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-06
Channels
- # aleph (15)
- # announcements (2)
- # babashka (121)
- # beginners (62)
- # biff (6)
- # cherry (2)
- # cider (51)
- # clerk (30)
- # cljs-dev (5)
- # clojure (77)
- # clojure-austin (2)
- # clojure-europe (10)
- # clojure-germany (6)
- # clojure-nl (1)
- # clojure-norway (19)
- # clojure-romania (1)
- # clojure-uk (3)
- # clojurescript (16)
- # core-typed (7)
- # cursive (17)
- # datomic (12)
- # deps-new (11)
- # emacs (7)
- # events (2)
- # fulcro (5)
- # honeysql (2)
- # hyperfiddle (32)
- # introduce-yourself (1)
- # jobs-discuss (2)
- # membrane (18)
- # missionary (2)
- # music (5)
- # polylith (7)
- # reagent (26)
- # releases (5)
- # testing (32)
- # tools-build (14)
- # tools-deps (7)
- # xtdb (8)
is there a way to name Reagent components without reagent.core/create-class
? With metadata, perhaps?
A form-1 component derives its name from the function.
A form-2 component derives its name from the outer function.
A form-3 component derives its name from the :display-name
property.
What are the scenarios where you don't see a proper name of a component?
just when something breaks, it says "error occurred in reagent8
component" or the like
I can typically figure out the source of the problem so it's not a big deal
ah yeah I fixed this error already but it did originate in a form-2 component, I had an extra set of brackets in my inner component that broke the render
With a form-2 component, the name is derived from the outer function, not the inner one. So unless the outer function was also without a name, it should've been handled correctly.
and I have the dubiously bad habit of not naming my anonymous functions even though I know that is supported
I usually don't name anonymous functions as well. :) Haven't had any problems with it though.
I recreated it and I see this
The above error occurred in the <reagent8> component:
cmp@http://localhost:8080/js/cljs-runtime/reagent.impl.component.js:508:43
div
shadow$provide.module$node_modules$react_daisyui$dist$react_daisyui_cjs/Card<@http://localhost:8080/js/cljs-runtime/module$node_modules$react_daisyui$dist$react_daisyui_cjs.js:98:293
cmp@http://localhost:8080/js/cljs-runtime/reagent.impl.component.js:508:43
div
div
div
cmp@http://localhost:8080/js/cljs-runtime/reagent.impl.component.js:508:43
div
cmp@http://localhost:8080/js/cljs-runtime/reagent.impl.component.js:508:43
Consider adding an error boundary to your tree to customize error handling behavior.
Visit to learn more about error boundaries.
the top line
dumbed down but it has this form
(defn outer-component []
(let [foo (atom nil)]
(fn []
[inner-component-that-breaks])))
where that extra set of brackets appears in the body of inner-component-that-breaks
is it because in this case it's a nested error (the top level exception being invalid arity: 0
) that the name gets wiped out?
Ah, when you have something like [[:div]]
, Reagent treats the outer [...]
as a Hiccup vector and its first item as the element.
[:div]
is an invalid element and you can't derive a useful name from it. So Reagent ends up generating one.
The only way to fix it while preserving the bug would be to use something like [^{:display-name "bad stuff"} [:div]]
. But at that point you would've noticed the issue already, I think.
indeed, I've developed a reasonable degree of proficiency at reading CLJS stacktraces at this point so wasn't too hard to sleuth out. More curiosity than anything. Thanks.
is there some React interop I'm missing here?
(defn Text []
(let [text (atom (inline "text_i.md"))
par-1 (inline "text_i_par_1.md")
handle-click (fn [_] (reset! text par-1))]
(fn []
[:> Card
[:> (.-Body Card)
[:> Markdown
{:options {:overrides
{:a {:component Link
:props {:class-name "link-primary"
:on-click handle-click}}}}} @text]]])))
This renders but clicking the link that appears in the text does nothing except tack the fragment (from the resulting Link
href) onto the routehmm, no dice. In both cases, I can see the onClick prop in the React DevTools.
Ah, alright, good to know. How Reagent works with nested properties is something I usually don't deal with so can never recall. :)
Mm, you used atom
. Shouldn't it be r/atom
?
aha! I am always doing that :melting_face: I even had an unused require of [reagent.core :as r]
taunting me