如何解决JavaScript UseState.map不是函数
我正在与reactjs一起尝试获取并列出页面中的事件。根据console.log(incidents),事件是一个空数组,但是当我运行它时,返回值为:
TypeError:accidents.map不是函数
index.js:67 []length: 0__proto__: Array(0)
index.js:67 []length: 0__proto__: Array(0)
index.js:22 {incidents: Array(2)}incidents: Array(2)0: {id: 7,titulo: "csa",desc: "dsadsa",valor: "dsa",ong_id: "857bc663"}1: {id: 8,titulo: "asf",desc: "sdf",valor: "d",ong_id: "857bc663"}length: 2__proto__: Array(0)__proto__: Object
index.js:67 {incidents: Array(2)}
index.js:67 {incidents: Array(2)}
{{1}}
解决方法
您的日志似乎表明response.data是一个对象,并且具有eventss数组作为属性。
您可以尝试替换:
setIncidents(response.data);
具有:
setIncidents(response.data.incidents);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。