I'm react Native beginner. I have write a code for fech data from API using "axios" npm package. When I run is running properly but when it is get data it is throw error.
undefined is not a function (evaluating 'this.setstate(
I suspect it's something wrong with this binding but I can't figure out how to fix it. Please help me to resolved this error.
Below is my code:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, ListView} from 'react-native';
import axios from 'axios';
export default class App extends Component {
constructor(props){
super(props);
this.state = {
isolate: true,
movies: []
}
}
componentWillMount(){
axios.get('https://facebook.github.io/react-native/movies.json')
.then(function (response){
var moviesList = new ListView.DataSource({
rowHasChanged: (r1,r2) => r1 !== r2
});
this.setState({
isolate: false,
movies: moviesList.cloneWithRows(response.data.movies)
});
}).catch(function(error){
alert(error);
});
}
render() {
if(this.state.isolate){
return (<View>
<Text>Loading....</Text>
</View>);
}
return (
<View style={styles.container}>
<ListView
dataSource={this.state.movies}
renderRow={
(rowData) => <Text> {rowData.title} </Text>
}
>
</ListView>
</View>
);
}
}
Thanks in advance.