import React from 'react';
import { FlatList, ActivityIndicator, Text, View } from 'react-native';
export default class FetchExample extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
let formData = new FormData();
formData.append("username","admin");
formData.append("password","admin");
return fetch('http://10.2.18.132:8088/user/auth',
{
method: "POST",
headers: {
// Accept: "application/json"
},
// body: JSON.stringify({
// username: "admin",
// password: "password"
// })
body:formData,
}
)
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
dataSource: responseJson.msg,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render(){
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return(
<Text>{this.state.dataSource}</Text>
);
}
}