1

我正在关注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)
4

1 回答 1

1

事实证明,这不是这里提到fulcro 问题

什么对我有用,就像添加此处指出的hoist-non-react-statics版本以及更新和软件包一样。3.3.0reactreact-dom

于 2019-10-31T17:11:53.597 回答