This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-02
Channels
- # announcements (1)
- # architecture (1)
- # aws (21)
- # babashka (37)
- # beginners (173)
- # boot (12)
- # chlorine-clover (5)
- # cider (36)
- # clara (11)
- # clj-kondo (25)
- # clojure (128)
- # clojure-europe (7)
- # clojure-finland (3)
- # clojure-germany (2)
- # clojure-nl (57)
- # clojure-uk (23)
- # clojurescript (71)
- # clojurex (1)
- # core-async (30)
- # core-typed (5)
- # cursive (35)
- # datomic (8)
- # duct (4)
- # emacs (8)
- # exercism (41)
- # fulcro (116)
- # jackdaw (4)
- # jobs-discuss (6)
- # juxt (4)
- # kaocha (16)
- # leiningen (14)
- # malli (5)
- # observability (4)
- # off-topic (2)
- # pathom (19)
- # pedestal (29)
- # re-frame (64)
- # reitit (18)
- # ring (8)
- # shadow-cljs (3)
- # sql (13)
- # tools-deps (32)
- # tree-sitter (5)
- # yada (17)
Hi! I'm using reitit-frontend
within a re-frame
project. I'm having trouble getting my subscription
for :current-route
to update properly when I refresh the page on a not /
page, e.g. /#/about
; views.cljs...
(defn main-panel []
(let [current-route @(subscribe [:current-route])]
(fn []
[:div
[:h1 "Hello World"]
[:p (str "Current Route: " (-> current-route :data :name))] ;; <----- :current-route initial value is nil, so this starts as empty string
])))
; router.cljs...
(defn on-navigate [new-match]
(when new-match
(do (prn "on-navigate ->")
(cljs.pprint/pprint new-match) ;; <---------------- prints the correct match, db updates current-route, but view is not re-rendered
(dispatch [:navigated new-match]))))
Might be a React quirk. Try this: before the first [:div
in main-panel
, put
^{:key (str "main-" (-> current-route :data :name))}
That will give React a kick in the pants to force a re-render of your div.
(I hope :hand_with_index_and_middle_fingers_crossed: )
(defn main-panel []
(let [current-route @(subscribe [:current-route])]
(fn []
^{:key (str "main-" (-> current-route :data :name))}
[:div
[:h1 "Hello World"]
[:p (str "Current Route: " (-> current-route :data :name))]
[match-name (-> current-route :data :name)]
])))
Hmm, the route name is changing, right? If so, then the other thing I’d try is moving the ^{:key...}
line down to just above the [:p...]
Oh wait, you want @(subscribe...)
inside your render function
Shouldn’t need the ^{:key...}
trick at all, just move the subscribe deref.
The subscribe
can be in an outer let, but the @
has to be inside the fn.
I’d have picked up on that quicker but I had to go off coffee for health reasons 😕