I am trying to fetch data from API on my localhost server using "Axios" in React Native but data in not fetching from API and displaying "TypeError: undefined is not an object (evaluating 'allRowIDs.length')" in the emulator.
Here is my code:
import React, { Component } from 'react';
import { StyleSheet, ActivityIndicator, ListView, Text, View, Alert } from 'react-native';
import axios from 'axios';
export default class pageOne extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: true,
}
}
async componentDidMount(){
try{
await axios.post('http://192.168.38.230/reactTest/list.php')
.then(response => {
console.log(response);
this.setState({isLoading: false, dataSource: response})})
.catch(err => console.log(err));
} catch(error){
console.log('Fetch Error:', error)
}
}
render() {
if (this.state.isLoading) {
return (
<View>
<ActivityIndicator />
</View>
);
}
return (
<ListView
dataSource={this.state.dataSource}
renderSeparator= {this.ListViewItemSeparator}
enableEmptySections = {true}
renderRow={(rowData) => <Text style={styles.rowViewContainer}
onPress={this.GetItem.bind(this, rowData.cl_name)} >{rowData.cl_name}</Text>}
/> );}}
And this is api data
[{"id":"1","cl_name":"test11"},{"id":"2","cl_name":"test12"},{"id":"3","cl_name":"test13"},{"id":"4","cl_name":"test14"}]