I'm having problem with setState function. This is my code:
class App extends Component {
constructor(props){
super(props);
this.state={
movies: [],
selectedMovie: null
}
this.movieSearch("kingsman")
}
movieSearch = (term) =>{
const request = axios.get(`${ROOT_URL}${API_KEY}&query=${term}`)
.then(function (response) {
let parsed = JSON.parse(response.request.response);
console.log(parsed);
this.setState({movies:parsed.results})
})
.catch(function (error) {
console.log(error);
});
}
.............
For some reason I get "TypeError: Cannot read property 'setState' of undefined" in my console. Could someone explain me what mistake I'm doing here?