Here's my code :
class App extends Component {
state = {
query: '',
results: []
}
handleSearch(e) {
var query = e.target.elements.query.value;
axios.get("http://www.omdbapi.com/?s=" + query + "&page=1&apikey=xxxx")
.then(function (response) {
console.log(response.data);
this.setState({
results: response.data.Search
});
}.bind(this))
.catch(function (error) {
});
e.preventDefault();
}
I'm trying to fetch data from omdb and show it on page.
the problem is setState not updating an array results?
Any idea ? Thanks
console.error(error);inside yourcatchfunction, does it log anything to the console? Do you get an error in the Network tab of your Developer Tools?handleSearchtothisin the constructor, or makehandleSearchinto a class property arrow function:handleSearch = (e) => { ... };