This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-02
Channels
- # announcements (37)
- # babashka (9)
- # beginners (172)
- # calva (7)
- # cestmeetup (28)
- # chlorine-clover (27)
- # clj-kondo (2)
- # cljs-dev (45)
- # cljsrn (8)
- # clojure (185)
- # clojure-dev (27)
- # clojure-europe (6)
- # clojure-finland (3)
- # clojure-nl (5)
- # clojure-uk (13)
- # clojuredesign-podcast (4)
- # clojurescript (54)
- # conjure (19)
- # core-typed (1)
- # cursive (40)
- # datomic (9)
- # emacs (5)
- # figwheel-main (34)
- # fulcro (238)
- # graphql (14)
- # hugsql (3)
- # leiningen (4)
- # malli (6)
- # off-topic (12)
- # pedestal (5)
- # portkey (19)
- # protorepl (8)
- # rdf (2)
- # re-frame (23)
- # reagent (3)
- # reitit (16)
- # shadow-cljs (29)
- # spacemacs (12)
- # sql (1)
- # xtdb (15)
anyone using antd with re-frame by any chance?
I'm having an issue with a checkbox inside an ant table, and using re-frame subscriptions inside it
{:id :selected
:title ""
:render (fn [{:keys [id]}]
(r/as-element
[ant/checkbox
{:key id
;; FIXME: this is needed to make the select all work correctly
;; :checked (contains? @(rf/subscribe [::handlers/selected-rows]) id)
:on-change #(rf/dispatch [::handlers/toggle-row id])}]))}
well 😄
no it was not commented out before
I just commented it out to have the checkbox working
I wonder if it's somehow related to the fact that I use r/as-element
instead of creating a more standard reagent component, and so it doesn't detect the fact there is a subscription?
we use r/as-element
in many places but never with a subscription inside, so I think it's a possible explanation
That's exactly what I was thinking. Seems like a good lead, but I don't have a deep enough knowledge of Reagent to confirm without experimenting.
Try to refactor the [ant/checkbox ...]
part into its own Reagent component, just so the subscribe
call doesn't happen directly in that fn
.
ah nice after doing
(defn row-checkbox
[{:keys [id]}]
[ant/checkbox
{:key id
:checked (contains? @(rf/subscribe [::handlers/selected-rows]) id)
:on-change #(rf/dispatch [::handlers/toggle-row id])}])
and :render #(r/as-element [row-checkbox (-> % js->clj keywordize-keys)])
it all worksI'm not exactly sure why though
NP. My guess is that that fn
that calls as-element
is not called directly during the rendering phase, and so deref'ing the ratom does not register it as a source of updates for the component. Or maybe simply using as-element
prevents that registration mechanism from working.
well I'm still using as-element
so your first guess is probably correct
Yeah, but now the subscription is wrapped in another component and not directly in an argument to as-element
.
ah yes sure
@U061V0GG2 Can you please share an opinion on the observed behavior? I couldn't find anything in the docs regarding using ratoms in as-element
.
Render fn probably wasn't converted to Reagent component by anything, so the ratoms couldn't register change listener. (r/as-component (fn ...))
might have worked.
But not sure where this render property is used
it's documented here https://ant.design/components/table/#Column
but yeah having it as a separate component/function works well already
given that code even when the subscriptions changes the checked status never changes, I suspect the re-render is not triggered