Fork me on GitHub
#reagent
<
2016-06-26
>
lwhorton03:06:52

if I’m using a lib exposing react components, and those components use refs, is reagent incompatible?

danielbraun08:06:17

refs work. use reagent.core/current-component to access "this", and then use .-refs

pesterhazy12:06:08

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

pesterhazy12:06:24

(my-ref being an atom)

lwhorton13:06:40

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?

pesterhazy14:06:02

right, yeah. "Internal refs" work with reagent without a problem.

lwhorton15:06:16

cool.. i figured out the root of my problem after your confirmation @pesterhazy … two reacts on the page from a bad module bundle

michal19:06:45

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?

pesterhazy20:06:45

@michal, can you show a snippet?

michal20:06:40

@pesterhazy: sure, here it is:

michal20:06:45

(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)))})))

michal21:06:08

(defn popularity-chart-should-update [ranking]
  (js/console.log "should-update?")
  false)

michal21:06:12

all functions are called except :should-component-update

pesterhazy21:06:55

I think should-component-update is only called when props or component state changes

pesterhazy21:06:09

but not if a ratom updates

pesterhazy21:06:17

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)

pesterhazy21:06:18

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

pesterhazy21:06:33

this should properly trigger should-component-update

pesterhazy21:06:34

(not 100% sure that's actually the problem, given that you say that component-did-update is called)

michal21:06:15

@pesterhazy: looks a bit complicated, but I will try it anyway. thanks for help 🙂

jiangts21:06:38

anybody know how to use react-bootstrap modals in reagent? I'm having trouble getting the modal to show and hide

jiangts21:06:21

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)

tawus22:06:05

In material-ui, react components take react components as parameters. How do we do something like that in reagent ?