1

我有以下平面列表:

[flat-list {
                   :data [{:name "a"}
                          {:name "b"}
                          {:name "c"}]
                   :render-item (fn [item] [text (:name item)])
                   :key-extractor #(random-uuid)
                   }
        ]

但它不起作用并给了我:

Invariant Violation: Objects are not valid as a React child (found: object with keys {name, id, class}). If you meant to render a collection of children, use an array instead.

我究竟做错了什么?

- 编辑 -

现在我有以下内容:

        [flat-list {
                    :data [{:name "a"}
                          {:name "b"}
                          {:name "c"}]
                    :render-item (fn [item-]

                                   (r/reactify-component
                                    [text (:name item-)]
                                    ))
                    :key-extractor #(:name %)
                    :content-container-style {:align-items "center"}
                    }
         ]


但我得到了错误:Functions are not valid as a React child. This may happen if you returns a Component instead of <Component/> from render. Or maybe you meant to call this function rather than return it.

使用 as-element 不会产生错误,但也不会呈现文本组件。

4

1 回答 1

1

只是因为 renderItem 等待了一个 react 组件

:render-item (fn [item] 
  (r/reactify-component [text (:name item)]))

:render-item (fn [item] 
  (r/as-element [text (:name item)]))
于 2020-03-10T10:09:05.877 回答