Fork me on GitHub
#reagent
<
2020-01-10
>
lilactown00:01:16

you can use React Hooks libraries as long as you use them in functional components

kenny02:01:08

Huh, interesting. Will try that out. Thanks!

jffry15:01:22

Hello! I've got a question about the legitimacy of using add-watch on the reaction returned by r/track! (the eager version of track). Details in a post so it doesn't get too long in here:

p-himik16:01:02

I think you should be able to use reagent.ratom/run! to achieve the same while not requiring anything to be IWatchable.

p-himik16:01:14

Unless you need the previous value of the track.

jffry16:01:59

ah, that looks like just what I need. thanks!

👍 4
Lukas17:01:52

Hi there, i'm fairly new to reagent and trying to write a component that saves the state of which card got clicked at last (and display it differently than). My approach is the following:

(defn cards []
  (r/with-let [selected-card (r/atom nil)]
              [:div.container>div.columns.is-multiline.is-centered
               (doall
                 (for [item @(rf/subscribe [:sequence])]
                   [:div.column.is-narrow>div.playing-card
                    {:on-click #(reset! selected-card item)
                     :class    (when (= item @selected-card :is-active))
                     :key      item}
                    [:h1.has-text-centered.has-text-weight-bold.is-size-1 item]]))]))
but this doesn't work and i can't figure out why. I logged this expression (when (= item @selected-card :is-active)) and it evaluates to true. Without the condition :is-active also works. Any help is greatly appreciated.

p-himik17:01:34

You have :is-active inside the condition. The body of when ends up being empty, which evaluates to nil.

p-himik17:01:15

And the condition probably never becomes true either with that :is-active there. :)

Lukas17:01:45

Great thanks a lot

arttuka17:01:34

please put the re-frame subscription inside the with-let bindings and not in the body of the render function. that way the subscription will only be made once. doing it your way will afaik cause a memory leak and at least causes unnecessary computation.

p-himik17:01:08

No it will not. Subs are cached.

arttuka17:01:03

has this changed? when I learned re-frame, the guide was to always create the subscription outside the render function, then just deref it in the render function?

p-himik17:01:57

Yep, more than 3 years ago.

juhoteperi17:01:01

0.9.0 (2016.12.15) • #218 Make it okay to use `subscribe` in Form-1 components. This is a big deal.

Lukas17:01:23

would it be more idiomatic anyways?

arttuka17:01:46

nice, that is definitely something I have missed

p-himik18:01:49

@UP2FUP0TT That can be used as an argument, yes. But in this case, I see this difference as very minor, especially given the subs cache.

Lukas17:01:30

Thank you, you guys rock