Как использовать flat-list в ренатальном периоде? - PullRequest
1 голос
/ 09 марта 2020

У меня есть следующий плоский список:

[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 не дает ошибку, но также не отображает текстовые компоненты.

1 Ответ

1 голос
/ 10 марта 2020

Это просто потому, что renderItem ожидает реагирующий компонент

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

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