3

我看到很多这样的代码:

(defn simple-component []
  [:div
   [:p "I am a component!"]
   [:p "This component has two paragraphs"]])

有没有办法使该组件只有两个 p 元素,而没有封闭的 div?

4

2 回答 2

1

这似乎是“菜鸟错误”。请查看此 wiki 页面:Form-1: A Simple Function https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components

于 2015-08-04T11:15:39.113 回答
1

您可以使用可以通过两种方式创建的反应片段来做到这一点:

  1. 使用 js 数组(采用反应元素):

    (defn simple-component []
          #js [(r/as-element [:p "I am a component!"])
               (r/as-element [:p "This component has two paragraphs"])])
    
  2. 使用[:<> ... ]标签(采用打嗝形式):

    (defn simple-component []
          [:<>
              [:p "I am a component!"]
              [:p "This component has two paragraphs"]])
    

在这个 PR 中实现

于 2020-05-04T17:52:07.300 回答