I'm following the Fulcro 3 Dev Guide, section Using Javascript React Components, with the Fulcro Template project, trying to import the Material-UI React components.
I added the package with npm install --save @material-ui/core
and modified the demo_ws.cljs
file
(ns app.demo-ws
(:require [com.fulcrologic.fulcro.components :as fp]
[nubank.workspaces.core :as ws]
[nubank.workspaces.card-types.fulcro3 :as ct.fulcro]
[com.fulcrologic.fulcro.mutations :as fm]
[com.fulcrologic.fulcro.dom :as dom]
["@material-ui/core/Button" :default material-button]
[com.fulcrologic.fulcro.algorithms.react-interop :as interop]
))
(def ui-button (interop/react-factory material-button))
(fp/defsc FulcroDemo
[this {:keys [counter]}]
{:initial-state (fn [_] {:counter 0})
:ident (fn [] [::id "singleton"])
:query [:counter]}
(dom/div
(str "Fulcro counter demo [" counter "] ")
(ui-button
{:variant "contained"
:color "primary"}
"Another Button")
(dom/button {:onClick #(fm/set-value! this :counter (inc counter))} "+")))
(ws/defcard fulcro-demo-card
(ct.fulcro/fulcro-card
{::ct.fulcro/root FulcroDemo
::ct.fulcro/wrap-root? true}))
and having the error in the console:
Uncaught TypeError: Cannot read property 'root' of undefined
at eval (Button.js:323)
at renderWithHooks (react-dom.development.js:16242)
at updateForwardRef (react-dom.development.js:18125)
at beginWork$1 (react-dom.development.js:20187)
at HTMLUnknownElement.callCallback (react-dom.development.js:337)
at Object.invokeGuardedCallbackImpl (react-dom.development.js:386)
at invokeGuardedCallback (react-dom.development.js:441)
at beginWork$$1 (react-dom.development.js:25739)
at performUnitOfWork (react-dom.development.js:24666)
at workLoopSync (react-dom.development.js:24639)
It turns out that it wasn't a fulcro issue as mentioned in this places.
What worked for me, as was adding the
hoist-non-react-statics
version3.3.0
as pointed here and updatingreact
andreact-dom
packages.