Search code examples
clojurescriptreagent

form-3 component not rerendering anything even though :component-did-update is called


I have the following code to test out form-3 components:

(defn inner [data]
  (reagent/create-class
   {:display-name "Counter"

    :component-did-mount (fn []
                           (js/console.log "Initialized")
                           [:h1 "Initialized! " data])


    :component-did-update (fn [this _]
                            (let [[_ data] (reagent/argv this)]
                              (js/console.log (str "Updated " data))
                              [:div (str "My clicks " data)]))

    :reagent-render (fn [] [:div (str "My clicks " data)])}))

I am able to successfully trigger both the :component-did-mount and the :component-did-update as there is the expected output in the console log. However, neither of the two functions actually change anything on the page. It just shows the initial state of [:div (str "My clicks " data)] the whole time.

What am I doing wrong? Ps. I have read the reagent docs and the purelyfunctional guide.


Solution

  • You have to repeat the parameters in the :reagent-render function:

    (fn [data] [:div (str "My clicks " data)])