【问题标题】:reagent/adapt-react-class fails with :optimizations :advanced试剂/适应反应类因 :optimizations :advanced 而失败
【发布时间】:2017-11-13 19:53:34
【问题描述】:

我正在导入一个 react component(使用 :npm-deps 支持)并使用 adapt-react-class 适配器进行包装:

(:require [reagent.core :as reagent]
          [react-helmet]) 

(def meta-tags* (reagent/adapt-react-class (aget react-helmet "default")))

(defn main-panel []
  (let []
    (fn []
      [meta-tags*])))

这适用于开发,但是当高级编译器打开时:

未捕获的类型错误:无法将类作为函数调用

最小回购: https://github.com/fbielejec/npm-deps-demo

【问题讨论】:

标签: reactjs clojurescript reagent


【解决方案1】:

meta-tags* 是一个类,但您试图通过将它放在 Reagent 方括号内(即meta-tags*)来像函数一样调用它。

在您发布在 GitHub 上的源代码中,您还定义了一个名为 meta-tags 的函数。您似乎不小心误拨了meta-tags*。您的完整代码(基于 Github 演示)应为:

(ns app.views
  (:require [reagent.core :as reagent]
            [react-helmet]))

(def meta-tags* (reagent/adapt-react-class (aget react-helmet "default")))

(defn meta-tags [{:keys [:title :description]
                  :or {title "Some title"
                       description "some description"}}]
  [meta-tags* {:id "app-meta-tags"}
   [:title {:id "title" :title title}]
   [:meta {:id "description" :content description}]])

(defn main-panel []
  (let []
    (fn []
      [:div.container
       [meta-tags] ; <- no * star!
       [:h1 "Check for the meta-tags presence"]])))

【讨论】:

  • 他感谢您的回答。我不认为这会产生任何影响,元标记功能只是适应组件的包装器。为了方便起见,我只是简化了代码 sn-p。 github 代码与您在此处粘贴的内容是 1-1。
  • 我尝试进一步将最小回购简化为github.com/VaclavSynacek/npm-deps-demo,但仍然无法使其正常工作。斯科特建议的met-tags*meta-tags 的问题是我们考虑的问题,但仍然没有工作结果。
猜你喜欢
  • 2022-12-07
  • 2015-12-08
  • 2014-04-09
  • 2022-06-17
  • 2021-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多