Skip to content Skip to sidebar Skip to footer

Reactjs Listview To React Native Listview

My target is to convert react listView to working react-native ListView. First code is working reactJs code, second is my react-native try. Main issue is that I need replacement fo

Solution 1:

Check the ListView docs. The data source property takes an instance of ListViewDataSource, not an array of your data.

The docs show a minimal example implementation:

getInitialState: function() {
  var ds = newListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
  return {
    dataSource: ds.cloneWithRows(['row 1', 'row 2']),
  };
},

render: function() {
  return (
    <ListViewdataSource={this.state.dataSource}renderRow={(rowData) =><Text>{rowData}</Text>}
    />
  );
},

Solution 2:

Adding componentWillReceiveProps solve the problem:

componentWillReceiveProps(newProps) {
  this.setState({
    dataSource: this.state.dataSource.cloneWithRows(newProps.data),
  });
}

Post a Comment for "Reactjs Listview To React Native Listview"