This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-26
Channels
- # admin-announcements (3)
- # beginners (44)
- # boot (48)
- # cljs-dev (2)
- # cljsjs (14)
- # cljsrn (2)
- # clojure (32)
- # clojure-android (1)
- # clojure-nl (1)
- # clojure-portugal (1)
- # clojure-russia (7)
- # clojure-spec (51)
- # clojure-uk (21)
- # clojurescript (9)
- # component (2)
- # cursive (4)
- # emacs (5)
- # funcool (1)
- # hispano (3)
- # hoplon (10)
- # immutant (14)
- # jobs (1)
- # jobs-discuss (4)
- # off-topic (15)
- # om (1)
- # onyx (1)
- # planck (36)
- # re-frame (2)
- # reagent (25)
- # spacemacs (2)
- # spirituality-ethics (10)
- # untangled (2)
- # vim (8)
- # yada (1)
if I’m using a lib exposing react components, and those components use refs, is reagent incompatible?
refs work. use reagent.core/current-component to access "this", and then use .-refs
lwhorton: better yet, use the newish ref callback attribute to (fn [cmp] (reset my-ref cmp))
. This allows you to access the child component like this: (some-> @my-ref .focus)
or whatever
(my-ref being an atom)
i see.. but I shouldn’t need to do this for each component exposed by a lib, right? those “internal refs” should work wihout modification?
right, yeah. "Internal refs" work with reagent without a problem.
cool.. i figured out the root of my problem after your confirmation @pesterhazy … two reacts on the page from a bad module bundle
hey there. I have a problem trying to use :should-component-update
. component is created with r/create-class and that particular function is simply not called. any hints?
@michal, can you show a snippet?
@pesterhazy: sure, here it is:
(defn popularity-chart-container []
(let [ranking (subscribe [:subjects])]
(r/create-class {:display-name "popularity component"
:component-did-mount popularity-chart-did-mount
:reagent-render #(popularity-chart-render @ranking)
:should-component-update #(popularity-chart-should-update @ranking)
:component-will-update #(popularity-chart-will-update @ranking)
:component-did-update #(popularity-chart-did-update % (take 10 (sort-by-values @ranking)))})))
(defn popularity-chart-should-update [ranking]
(js/console.log "should-update?")
false)
I think should-component-update is only called when props or component state changes
but not if a ratom updates
which is what happens with subscribe
(I believe reagent calls forceUpdate
on the components it considers dirty, which doesn't require a should-component-update check)
a workaround may be to use the "container component" pattern: https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.jhmglsx17
use two components. the outer components derefs the ratom (via subscribe) and passes the data to be shown to the inner component as a prop
this should properly trigger should-component-update
(not 100% sure that's actually the problem, given that you say that component-did-update is called)
@pesterhazy: looks a bit complicated, but I will try it anyway. thanks for help 🙂
anybody know how to use react-bootstrap modals in reagent? I'm having trouble getting the modal to show and hide
reading this example, https://react-bootstrap.github.io/components.html#modals-live, it also looks like the close button needs an attribute without a value (not sure how to accomplish)