I am new to React.I am facing this error.I have the code which is pasted below.Please help get out of this error.
import React from 'react';
import { Card} from 'semantic-ui-react';
import axios from 'axios';
export default class PersonList extends React.Component {
state = {
persons: []
}
componentDidMount() {
axios.get(`http://localhost:8080/locations`)
.then(res => {
const persons = res.data;
this.setState({ persons });
})
}
render() {
return (
<div class="ui stackable two column grid">
{ this.state.persons.map(person =>
<div class="column">
<Card
header={person.LOCATION}
/>
</div>)
}
</div>
)
}
}
The error message is pasted below
TypeError: this.state.persons.map is not a function
PersonList.render
C:/Users/user/Desktop/src/Sample.js:22
19 | render() {
20 | return (
21 | <div class="ui stackable two column grid">
> 22 | { this.state.persons.map(person =>
23 | <div class="column">
Output of console.log('data', res.data)
:
{LOCATION: "CHINA9, SWEDEN9, CANADA9, austin, ", searchKey: {…}}
I request anyone to figure me out this error.