Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invariant Violation: ListView has been removed. But

I have this code from courses, and how I understand my mistake, that ListView has been removed from ReactNative. How can I fix the problem?

I've tried to replace all ListView tag to FlatList. But didn't work out.

class LibraryList extends Component {
 componentWillMount() {
   const ds = new ListView.DataSource({
    rowHasChanged: (r1, r2) => r1 !== r2
 });

  this.dataSource = ds.cloneWithRows(this.props.libraries);
 }

renderRow(library) {
  return <ListItem library={library} />;
}

render() {
  return (
   <ListView
     dataSource={this.dataSource}
     renderRow={this.renderRow}
    />
   );
  }
}
like image 444
bekanur98 Avatar asked Jul 18 '19 10:07

bekanur98


2 Answers

List VIew is deprecated in react native 0.60. So the quick fix is to use deprecated-react-native-listview

Need to add

import ListView from "deprecated-react-native-listview";

instead of

import ListView from from 'react-native';

https://www.npmjs.com/package/deprecated-react-native-listview

like image 122
Siddharth Chauhan Avatar answered Nov 19 '22 12:11

Siddharth Chauhan


class LibraryList extends Component{
    renderRow({item}) {
        return <ListItem library = { item } />;
    }

    render() {
        return(
            <FlatList
                data = {this.props.libraries}
                renderItem = {this.renderRow}
            />
        );
    }
}
like image 8
M.Hassam Yahya Avatar answered Nov 19 '22 11:11

M.Hassam Yahya