Below code returns an error for me Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined
I am new to react and this seems very basic. Any suggestion what could I be doing wrong. From the json result I want to store all names in my array.
import React, { Component } from "react";
class Search extends Component {
constructor(props) {
super(props);
this.state = {
list: [],
}
}
Search() {
fetch("http://url/getSearchResults")
.then(res => res.json())
.then(
(res) => {
this.setState({
list: res.data.name
})
})
}