繁体   English   中英

如何在重生中使用flat-list?

[英]How to use flat-list in re-natal?

我有以下平面列表:

[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. 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 不会出现错误,但也不会呈现文本组件。

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

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

:render-item (fn [item] 
  (r/as-element [text (:name item)]))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM