我正在关注Fulcro 3 开发指南,使用 Javascript React 组件部分,使用Fulcro 模板项目,尝试导入Material-UI React 组件。
我添加了包npm install --save @material-ui/core
并修改了demo_ws.cljs
文件
(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}))
并在控制台中出现错误:
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)