未处理的拒绝(TypeError):this.state.persons.map不是函数

时间:2020-05-04 15:22:43

标签: django reactjs

我正在使用react和django构建网站,但是我似乎被困在这里。我已经在网上检查了解决方案,但似乎无法找到这里的代码和错误。error screenshot

未捕获的TypeError:this.state.persons.map不是函数

import React from "react";
import axios from "axios";
import {
  Container,
  Dimmer,
  Image,
  Item,
  Label,
  Loader,
  Message,
  Segment
} from "semantic-ui-react";
import { productListURL } from "../constants";

export default class ProductList extends React.Component {
  state = {
    persons:[]
  };

  componentDidMount(){
    axios.get(productListURL)
    .then(res =>{
      const persons = res.data;
      this.setState({persons});
    })
  }

  render(){
    return (
      <ul>
        {this.state.persons.map(person => <li>{person.title}</li>)}
      </ul>
    )
  }
}

0 个答案:

没有答案