Ответ 1
Попробуйте настроить ListView DataSource как переменную многократного использования, а затем повторно использовать ее, когда вам это нужно. Кроме того, вам может потребоваться установить dataSource как пустой массив, пока ваши данные не войдут. Попробуйте что-то вроде этого:
var ds = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2 })
class Movies extends Component {
render() {
if (this.state.dataSource.getRowCount() === 0) {
return (
<View style={styles.container}>
<Text>
loading....
</Text>
</View>
);
}
else {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow.bind(this)}
/>
</View>
);
}
}
constructor(props){
super(props);
this.state = {
dataSource: ds.cloneWithRows([]),
};
}
componentWillMount() {
this.fetchData();
}
fetchData(){
fetch(HOT_MOVIES_URL)
.then((response) => response.json())
.then((responseData) => {
if (responseData) {
this.setState({
dataSource: ds.cloneWithRows(responseData),
});
}
})
.done();
}
}