The data-source property isn't propagated from reagent to the render method of the React Native ListView component

eploko

I'm trying to render a React Native ListView in reagent.

I have the following snippet:

(def data-source
 (React.ListView.DataSource. #js{:rowHasChanged (fn [a b] false)}))

(defn render-row []
  [ui/view])

(def rows
  (clj->js ["whoa", "hey"]))

(defn main-scene []
  (fn []
    [ui/list-view {:render-row render-row
                   :data-source (.cloneWithRows data-source rows)}]))

The above leads to "Failed propType: Required prop dataSource was not specified in ListView. Check the render method of app.ios.ui.main_scene." Which is followed by "Cannot read property 'rowIdentities' of undefined" as the data source is undefined inside the render method of the ListView.

My first guess was there was some special treatment of the "data-" attributes somewhere in the internals of either reagent/hiccup or whatever, but I couldn’t find a single clue to why the property is not propagated properly.

And, yep, (.cloneWithRows data-source rows) actually returns a valid ListViewDataSource object instance.

And then if I pass :data-source as :dataSource all I get is a puzzling "StaticRenderer.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object."

I’m using react-native 0.18.1 and reagent 0.5.1 with re-frame 0.6.0. I have checked this with reagent 0.6.0-alpha and re-frame 0.7.0-alpha and got the same errors.

I've been digging this for several hours and I guess I need some help. Any hints/ideas to try to fix this, any references in the code to look at? Thanks a ton in advance.

eploko

Well, the first thing is the data source should be passed to the view as :dataSource and not as :data-source. The latter doesn’t work for whatever reason. As a side note, the render row method can both be passed as :render-row or :renderRow and it works both ways. Heh.

Secondly, the render-row function should return a React component and not an array. The latter would be okay if the array was later rendered by reagent, but the listview doesn’t do any kind of post-processing on the data it gets from render-row and merely tries to return that to React, which bails if it’s a plain clojure array.

So the above render-row function should be written as:

(defn render-row []
  (r/as-element [ui/view]))

And then everything works fine. :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

React native: ListView doesn't render a row

From Dev

How to render component from a function outside the render method in React?

From Dev

React Native FlatList - Calling A Function In The Render Method Which Returns A Component

From Dev

React call component's method from nested function in render method

From Dev

React Native - ListView not rendering data from Firebase

From Dev

React Native - Passing data from a component to another

From Dev

Can I make a React component re-render itself when it's attribute is a reactive data source from Meteor?

From Dev

Scroll event isn't propagated to parent

From Dev

React route couldn't render component with passing data

From Dev

React: how to render data into a component?

From Dev

Component won't render in react

From Dev

React/Flux: Firing an action from a render method of an component or doing a Rest call from a component?

From Dev

can't render <MapView/> from react-native-maps

From Dev

Why isn't my ListView displaying new elements from its source?

From Dev

Calling a method of a parent component from child - React Native

From Dev

Render a component onPress(TouchableOpacity/Button) in React Native

From Dev

How to render component with ajax in react native?

From Dev

react native render another component in main

From Dev

Express' render/redirect does not work if the call isn't coming from a submit method in a form

From Dev

Return JSX from component method to render method

From Dev

onClick event isn't firing on React Component

From Dev

onClick event isn't firing on React Component

From Dev

React Native - Force ListView Re-render when data has not changed

From Dev

React Native - Force ListView Re-render when data has not changed

From Dev

React Native - How to prepend AND append data in ListView without full re-render

From Dev

The tag 'Link' only change the URI, the component isn't render

From Dev

Search data in ListView react native

From Dev

Search data in ListView react native

From Dev

React render method not called for nested component

Related Related

  1. 1

    React native: ListView doesn't render a row

  2. 2

    How to render component from a function outside the render method in React?

  3. 3

    React Native FlatList - Calling A Function In The Render Method Which Returns A Component

  4. 4

    React call component's method from nested function in render method

  5. 5

    React Native - ListView not rendering data from Firebase

  6. 6

    React Native - Passing data from a component to another

  7. 7

    Can I make a React component re-render itself when it's attribute is a reactive data source from Meteor?

  8. 8

    Scroll event isn't propagated to parent

  9. 9

    React route couldn't render component with passing data

  10. 10

    React: how to render data into a component?

  11. 11

    Component won't render in react

  12. 12

    React/Flux: Firing an action from a render method of an component or doing a Rest call from a component?

  13. 13

    can't render <MapView/> from react-native-maps

  14. 14

    Why isn't my ListView displaying new elements from its source?

  15. 15

    Calling a method of a parent component from child - React Native

  16. 16

    Render a component onPress(TouchableOpacity/Button) in React Native

  17. 17

    How to render component with ajax in react native?

  18. 18

    react native render another component in main

  19. 19

    Express' render/redirect does not work if the call isn't coming from a submit method in a form

  20. 20

    Return JSX from component method to render method

  21. 21

    onClick event isn't firing on React Component

  22. 22

    onClick event isn't firing on React Component

  23. 23

    React Native - Force ListView Re-render when data has not changed

  24. 24

    React Native - Force ListView Re-render when data has not changed

  25. 25

    React Native - How to prepend AND append data in ListView without full re-render

  26. 26

    The tag 'Link' only change the URI, the component isn't render

  27. 27

    Search data in ListView react native

  28. 28

    Search data in ListView react native

  29. 29

    React render method not called for nested component

HotTag

Archive