Unhandled Rejection (TypeError):this.setState is not a function

Michael S
2 min readJan 2, 2019

--

Use arrow function

Before :

class App extends React.Component {
state = { images: []}
...async onSearchSubmit(term) {
const response = await axios
.get('https://api.unsplash.com/search/photos', {
params: { query: term },
headers: {
Authorization: 'Client-ID
}
})
this.setState({ images: response.data.results });console.log('onSearchSubmit this : ', this)}...

After :

class App extends React.Component {
state = { images: []}
...onSearchSubmit = async (term) => {
const response = await axios
.get('https://api.unsplash.com/search/photos', {
params: { query: term },
headers: {
Authorization: 'Client-ID
}
})
this.setState({ images: response.data.results });console.log('App this : ', this)}...

I am blogging what I’ve learned to find later here for myself. If you happened to read this shit and there is wrong information, it would be appreciated to add a comment below.

--

--