Fork me on GitHub
#reagent
<
2018-02-14
>
derpocious03:02:05

Hey all, I'm getting a random error "Cannot read property 'call' of null" with no line number for my root component. What should I do?

derpocious03:02:01

(ns bakery-app.components.root-component
  (:require [re-frame.core :as re-frame]
            [bakery-app.reframe.subs :as subs]
            [reagent.core :as reagent]
            [bakery-app.reframe.events :as events]
            [bakery-app.reframe.handlers :as handlers]
            [bakery-app.components.container.product-list :as product-list]
            [bakery-app.components.container.shopping-cart :as shopping-cart]
            ))

(defn root-component []
  (let [name (re-frame/subscribe [::subs/name])]

    (reagent/create-class                 ;; <-- expects a map of functions
      {:component-did-mount               ;; the name of a lifecycle function
                      #((re-frame/dispatch [::handlers/load-product-list]))

       ;; other lifecycle funcs can go in here

       :display-name  "mail-panel"  ;; for more helpful warnings & errors

       :render        ;; Note:  is not :render
                      (fn []           ;; remember to repeat parameters
                        [:div {:class "root-component"}

                         [product-list/product-list-component]
                         [shopping-cart/shopping-cart-component]
                         ]

                         )})))

derpocious03:02:18

and my core.cljs

derpocious03:02:22

(ns bakery-app.core
  (:require [reagent.core :as reagent]
            [re-frame.core :as re-frame]
            [bakery-app.reframe.events :as events]
            [bakery-app.components.root-component :as view]
            [bakery-app.config :as config]
            [bakery-app.reframe.handlers :as handlers]))


(defn dev-setup []
  (when config/debug?
    (enable-console-print!)
    (println "dev mode")))

(defn mount-root []
  (re-frame/clear-subscription-cache!)
  (reagent/render [view/root-component]
                  (.getElementById js/document "app")))

(defn ^:export init []
  (re-frame/dispatch-sync [::events/initialize-db])
  (dev-setup)
  (mount-root))

derpocious03:02:43

I think I figured it out actually

derpocious03:02:03

the component-did-mount seems to like (fn [] (re-frame/dispatch [::handlers/load-product-list])) vs the shortcut #()