我看到很多像这样的代码:
(defn simple-component []
[:div
[:p "I am a component!"]
[:p "This component has two paragraphs"]])
有没有办法让该组件只有两个p元素,没有封闭的div?
答案 0 :(得分:1)
答案 1 :(得分:0)
您可以使用可通过两种方式创建的react片段来做到这一点:
带有js数组(带有react元素):
(defn simple-component []
#js [(r/as-element [:p "I am a component!"])
(r/as-element [:p "This component has two paragraphs"])])
带有[:<> ... ]
标签(采用打h形式):
(defn simple-component []
[:<>
[:p "I am a component!"]
[:p "This component has two paragraphs"]])