Fork me on GitHub
#reagent
<
2019-10-28
>
David Pham07:10:08

Why not using the component directly with :>. Similar to material-ui

Pavel Klavík08:10:31

How would that look?

Matt Butler19:10:49

When defining Form 2 components should the outer and render function always take the same number of args? Or is there a valid use case for diverging from this pattern?

lilactown19:10:01

they effectively take the same arguments, but you might ignore some in initial render vs. subsequent renders so you can be lazy and leave them out

lilactown19:10:07

(I think this is bad practice)

lilactown19:10:32

e.g.:

(defn my-component [styles initialization-data]
  (let [subscription (subscribe-with-initialization initialization-data)]j
    (fn [styles] ;; <-- we leave out initialization-data because we don't use it on subsequent renders
      [:div (prn @subsription)])))

Matt Butler19:10:44

Yeah, I know the general advice is to match arity, wondered if people had experience where they had good reason not to follow this.

oconn19:10:22

I guess if you wanted access to the initial value only (not sure the use case there though)

Matt Butler19:10:11

Funny you should link said example, I just felt the pain of this approach. To the consumer it's not clear when invoking the component which args will only be used on init.

Matt Butler19:10:55

Is there any benefit over this vs still including it but with a _ as the binding?

Matt Butler19:10:27

Maybe unnecessary render calls if init-data changes a lot.

lilactown19:10:48

the returned fn will be called whenever init-data changes whether or not it is included in the arguments

lilactown19:10:05

I think it’s always better to use _ to signal that it is not used

lilactown19:10:02

I also have a personal rule that I always accept a single map of arguments (a la raw React) instead of taking an ever increasing number of order-reliant arguments, but I understand that I can’t force that on everyone

oconn19:10:12

^ Great advice - I started transitioning all my view components to follow that pattern and it’s simplified quite a bit

dominicm21:10:46

As a rule of thumb, only using an argument on init is a bad sign. There's some react documentation on a edge case where that isn't true (and a handful of other barbaric libraries where I also needed to do it)

dominicm21:10:59

I don't see it often at all.