Real Source List with Real-Time Results

I am trying to create my own ListView that displays the results returned by Realm. I follow the instructions I found regarding the interactive ListView and how to use Realm.

However, I always get the same error: Objects are not valid as a React child (found: [object Results]). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of 'Text'.

From what I understand from the Realm documentation and other articles, the Results object should behave like a javascript list and therefore should be accepted in the cloneWithRows method.

If someone can tell me what I am doing wrong, or how to fix it, it would be very grateful.

PS I tried both responsive and ListView and Realm ListView, and both behave the same.

import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    Navigator,
    TouchableHighlight,
    TouchableOpacity,
    //ListView,
} from 'react-native';
import { ListView } from 'realm/react-native';

import realm from './myrealm'

class contextview extends Component {
    getState() {
        console.log("getInitialState");
        var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
        let pictures = [ realm.objects('picture').filtered('new == true') ];
        console.log("pictures: " + pictures);
        return {
            //dataSource: ds.cloneWithRows(['row 1', 'row 2', 'row 3']),
            dataSource: ds.cloneWithRows(pictures)
        };
    }

    constructor(props)
    {
        super(props);
        this.state = this.getState();
        this.bindMethods();
    }

    render() {
      return (
        <ListView
          dataSource={this.state.dataSource}
          renderRow={(rowData) => <Text>{rowData}</Text>}
        />
      );
    }
}
+4
source share
2

, ,

:

render() {
  return (
    <ListView
      dataSource={this.state.dataSource}
      renderRow={(rowData) => <Text>{rowData}</Text>}
    />
  );
}

:

render() {
  return (
    <ListView
      dataSource={this.state.dataSource}
      renderRow={(rowData) => <Text>{rowData.path}</Text>}
    />
  );
}

rowData ReactNative, Text

0

cloneWithRows? , Realm.ListView cloneWithRows Realm.Results. Realm . , , Realm.ListView :

let pictures = [ realm.objects('picture').filtered('new == true').snapshot() ];
0

Source: https://habr.com/ru/post/1648959/


All Articles