Skip to content

Instantly share code, notes, and snippets.

@streetsmartdev
Created August 9, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save streetsmartdev/f07420697fbf686e7ff872d7b897f4e5 to your computer and use it in GitHub Desktop.
Save streetsmartdev/f07420697fbf686e7ff872d7b897f4e5 to your computer and use it in GitHub Desktop.
RN-LFVL-2 - Remove the DataSource references
export default class Application extends Component {
constructor(props) {
...
this.state = {
dataSource: null, // remove this dataSource
isLoading: true,
isLoadingMore: false,
_data: null,
_dataAfter: ""
};
}
...
_fetchMore() {
this.fetchData(responseJson => {
const data = this.state._data.concat(responseJson.data.children);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(data), //Remove this cloneWithRows
isLoadingMore: false,
_data: data,
_dataAfter: responseJson.data.after
});
});
}
componentDidMount() {
this.fetchData(responseJson => {
//Remove the creation of ListView.DataSource instance
//let ds = new ListView.DataSource({
// rowHasChanged: (r1, r2) => r1 !== r2
//});
const data = responseJson.data.children;
this.setState({
dataSource: ds.cloneWithRows(data), //remove this dataSource reference
isLoading: false,
_data: data,
_dataAfter: responseJson.data.after
});
});
}
render() {
if (this.state.isLoading) {
...
} else {
return (
<FlatList
dataSource={this.state.dataSource} //Remove this reference to dataSource
renderRow={rowData => {
...
}}
...
/>
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment