Fork me on GitHub
#reagent
<
2015-11-13
>
chancerussell00:11:07

Hi all. Anyone know if there's a way to get the this reference in a :reagent-render function?

chancerussell00:11:56

Or am I stuck going with :render and using argv?

chancerussell00:11:15

Need to have both 😕

mikethompson00:11:06

In fact, just look back to the last code block.

chancerussell00:11:48

Yeah, saw that. Was hoping to get it the other direction, but I guess there’s no advantage or disadvantage

mikethompson00:11:21

Perhaps you want reagent.core/current-component

richiardiandrea04:11:17

Hello guys, maybe this has already been answered, but is there another way to layout dynamic components with Reagent? I found this but it looks convoluted..http://stackoverflow.com/q/25371926/1888507

grav07:11:05

@mikethompson: It’s to get a value out of an input field in the dom. It's legacy code, not the way I’d handle it, but I’d like to see how to handle these kinds of scenarios in Reagent.

grav07:11:50

In the current Om-based code, I’ll always have access to this in all lifecycle methods, so getting a DOM node is simple. Less so in Reagent, it seems

mikethompson07:11:37

(reagent.core/current-component) looks easy enough to me

grav07:11:54

Ooh - that’s nice 😄

mikethompson07:11:29

You can use that in the renderer

mikethompson07:11:50

But not in the lifecycle fns

mikethompson07:11:59

Anway, have a read of the above

grav07:11:37

Thanks, didn’t see your link before now

grav07:11:01

Oh, seems I have another problem, since I’m using refs. Is it correct that I’ll need to wrap all refs in components, since I cannot use React’s refs directly?

richiardiandrea18:11:02

@grav did you solve it? how did you access the laid-out DOM within, say, :component-did-mount ?

richiardiandrea19:11:10

I am using this approch now and I would like to ask if it is a good one:

(defn build-section-ui
  "Builds the UI for a section."
  [section]
  (let [name "section-ui-component"
        dynamic-map (reagent/atom {:topics {:min-width "20px"}})]

    (reagent/create-class
     {:display-name name
      :component-did-mount
      (fn []
        (reagent.debug/prn name "component-did-mount -> dyn-map" "dyn-map is" @dynamic-map)
        ;; change :min-width here
        )

      :reagent-render
      (fn [section]
        (reagent.debug/prn name "rendering -> dyn-map" @dynamic-map)
        [section-ui-render @dynamic-map section])})))

richiardiandrea20:11:25

is there a way to get a child of the this by name (or anything else) ?