reagent/adapt-react-class fails with :optimizations :advanced

感情迁移 提交于 2019-12-25 01:36:33

问题


I'm importing a react component (using the :npm-deps support) and wrapping with the adapt-react-class adapter:

(: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*])))

This works fine for development, but when advanced compiler is on:

Uncaught TypeError: Cannot call a class as a function

Minimimal repo: https://github.com/fbielejec/npm-deps-demo


回答1:


meta-tags* is a class, but you're trying to call it like a function by placing it inside the Reagent square braces i.e. meta-tags*.

In the source code that you posted on GitHub, you also define a function called meta-tags. It looks like you're accidentally calling meta-tags* by mistake. Your full code (based on the Github demo) should read:

(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"]])))


来源:https://stackoverflow.com/questions/47272447/reagent-adapt-react-class-fails-with-optimizations-advanced

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!