fulcro 2025-04-02

I'm missing something obvious here. Given an id from outside of Fulcro, I can get that into Fulcro's db with a mutation (here, inject-external-props). But I can't figure out how to use that id in a query. The following code is wrong, but I'm not sure what needs to change to make it work:

(defmutation inject-external-props [external-props]
  (action [{:keys [state]}]
          (swap! state assoc ::external-props external-props)))

(defonce fulcro-app (app/fulcro-app))

(defsc ReportName [this props]
  {:query [:report/id :report/name]
   :ident :report/id
   :initial-state {}}
  (dom/span (str "Report Name: " (:report/name props))))

(def ui-report-name (comp/factory ReportName))

(defsc Root [this props]
  ;; How can I access ::report-id here?
  {:query [{:report-name (comp/get-query ReportName)}]
   :initial-state {}}
  (ui-report-name (:report-name props)))

(defn start! [report-id]
  (comp/transact! fulcro-app [(inject-external-props {::report-id report-id})])
  (app/mount! fulcro-app Root "app"))

(get-in props [:report-name :report/id])

👍 1

the query restores the tree of props (which is what React needs…a tree of props from root)…so root can actually see the denormalized tree