export default class App extends React.Component {
constructor(props){
super(props);
this.state ={
isLoading: true,
_dataSource:[],
}
}
componentDidMount(){
return fetch('url minha api')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
_dataSource: responseJson.minhasinformacoes,
get dataSource() {
return this._dataSource;
},
set dataSource(value) {
this._dataSource = value;
},
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
setTimeout(() => {
this.setState({
_dataSource: this.state._dataSource + _dataSource
})
}, 1000);
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<View style={{flex: 1, paddingTop:20}}>
/*Quando houvesse mudanças atualizasse os campos ProductName e
CategoryName atuamaticamente*/
<FlatList
data={this.state._dataSource}
renderItem={({item}) => <Text>{item.ProductName}, {item.CategoryName} </Text>}
keyExtractor={({id}, index) => id}
/>
</View>
);
}
}
bold text