Fork me on GitHub
#reagent
<
2020-03-01
>
abdullahibra21:03:02

i'm trying to use chart.js but i have a problem in the delay of viewing the data, i'm using re-frame and i'm using that code:

ouvasam09:03:21

Hi, i think you don't need the fn partt here

(defn x-chart []
  (let [chart-labels (rf/subscribe [:x/x-labels])
        chart-data (rf/subscribe [:x/x-data])]
    (fn []
      [gen-x-chart @chart-labels @chart-data])
    ))
you could simply use

ouvasam09:03:41

(defn x-chart []
  (let [chart-labels (rf/subscribe [:x/x-labels])
        chart-data (rf/subscribe [:x/x-data])]
      [gen-x-chart @chart-labels @chart-data]
    ))

ouvasam09:03:46

also component-did-mount does not receive the same arguments. It receive props

ouvasam09:03:56

i'll try to make an exmaple

ouvasam09:03:30

defn chart
  [data]
  (r/create-class
   {:component-did-mount
    (fn [this]
      (println (r/props this)))
    :component-did-update
    (fn [this]
      (println "updated-data" (r/props this)))
    :reagent-render
    (fn [data]
      [:div (:label data) (:data data)])}))

ouvasam09:03:13

[chart {:label "label" :data [0 1 2]]

ouvasam09:03:18

hope this help

abdullahibra12:03:26

@U0F7M1KA7 thank you so much, i'll try that now

👍 4
abdullahibra21:03:39

the up-to-date data are shown at [:h1 (str (js->clj data))] but the chart is using step back data

abdullahibra21:03:48

i'm not sure what cause that delay