This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-16
Channels
- # announcements (1)
- # babashka (23)
- # beginners (157)
- # boot (3)
- # calva (2)
- # chlorine-clover (12)
- # cider (14)
- # clara (5)
- # clj-kondo (6)
- # cljs-dev (61)
- # cljsrn (30)
- # clojure (65)
- # clojure-argentina (8)
- # clojure-berlin (2)
- # clojure-europe (13)
- # clojure-france (9)
- # clojure-germany (2)
- # clojure-italy (4)
- # clojure-nl (6)
- # clojure-portugal (2)
- # clojure-romania (2)
- # clojure-uk (76)
- # clojurescript (56)
- # conjure (52)
- # core-async (37)
- # datomic (209)
- # duct (17)
- # emacs (17)
- # exercism (1)
- # fulcro (26)
- # graalvm (5)
- # instaparse (2)
- # jackdaw (9)
- # jobs-discuss (27)
- # joker (2)
- # juxt (23)
- # leiningen (4)
- # malli (11)
- # midje (3)
- # pedestal (2)
- # quil (2)
- # re-frame (78)
- # reagent (8)
- # reitit (18)
- # remote-jobs (1)
- # ring (2)
- # ring-swagger (1)
- # shadow-cljs (29)
- # sql (11)
- # test-check (12)
- # tools-deps (5)
- # xtdb (16)
- # yada (4)
created a pr to improve the doc about using react portals https://github.com/reagent-project/reagent/pull/488 (from the discussion in https://github.com/reagent-project/reagent/issues/418)
Hi, :spock-hand: a question about form 3 components. My app have a tabbed view of data for three little robots. I have a component, that renders a tab, and triggers a polling of some relevant data for the currently viewed robot. The active tab is an atom, so when I change it it re-renders the component:
(defn robot-panel []
(let [active-tab (re-frame/subscribe [::subs/active-tab])]
;;some other stuff
[robot-tab @active-tab]
;;some other stuff
))
Then, the robot-tab component, when mounted starts polling, and when unmounted stops polling
(defn robot-tab [n]
"renders a tab displaying fish feeding robot data"
(reagent/create-class
{:component-did-mount
(fn [this]
(request-robot n))
:component-will-unmount
(fn [this]
(release-robot n))
:reagent-render
(fn [n] [:<>
;;Some robot things that get rendered
])}))
However, when switching a robot tab,the component doesn't unmount and remount,
so the polling don't update.
I need to tell it to run
(release-robot old-n)
(request-robot new-n)
When it updates..
So I should probably store them in local state and use them in
:component-did-update
Thank you, that might be the solution https://emojipedia.org/face-with-tears-of-joy/
@ozfraier You can control when the component is unmounted and remounted by changing its identity - React key. If you only change the props, the component is the same, but it is just re-rendered. ^{:key robot-id} [robot-tab n]
would unmount the old robot-tab component and create new when the robot-id
value changes.
(robot-id = n probably here)
Thank you @juhoteperi, It works! Edited: I had a bug here but it was caused by something else...