I am new in react-native.I am unable to get "present" data from my API and I am getting an error "cannot read property present" so i just want to get my API response.Here is my api data and please check my code too.
{
"message": "present in this month",
"data": [
{
"present": 10
}
],
"status": "1"
}
async componentDidMount() {
try {
const DEMO_TOKEN = await AsyncStorage.getItem('isLoggedIn');
if (DEMO_TOKEN != null) {
console.log('Token', DEMO_TOKEN);
fetch('http://104.197.28.169:3000/userPresentInThisMonth', {
method: 'GET',
headers: {
Authorization: 'Bearer ' + DEMO_TOKEN,
},
})
.then(response => response.json())
.then(responseJson => {
alert(responseJson)
console.log(responseJson);
this.setState({
presentmonthdata : responseJson,
});
});
}
} catch (error) {
alert(JSON.stringify(error));
console.error(error);
}
}
This is my Text value.
{this.state.presentmonthdata.data[0] &&
<Text style={{color: 'grey',fontSize: 30, fontWeight: 'bold', }}>
{this.state.presentmonthdata.data[0].present}
</Text>
}
this.state.presentmonthdata.data[0].presentthis.state.presentmonthdata.data[0] && this.state.presentmonthdata.data[0].present