Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs this.state.data.map不是函数_Reactjs_Facebook Graph Api - Fatal编程技术网

Reactjs this.state.data.map不是函数

Reactjs this.state.data.map不是函数,reactjs,facebook-graph-api,Reactjs,Facebook Graph Api,我正在使用React和Facebook图形API进行API调用 API工作正常,但映射方法正在显示 此.state.data.map不是一个函数 import React, { Component } from 'react'; import axios from 'axios'; class user extends Component { constructor(props){ super(props); this.state={

我正在使用React和Facebook图形API进行API调用

API工作正常,但映射方法正在显示

此.state.data.map
不是一个函数

import React, { Component } from 'react';
import axios from 'axios';

 class user extends Component {

    constructor(props){

        super(props);

        this.state={
            data:[123]
        }

    }
    componentDidMount() {
        axios.get("facebook url")
          .then(response => {
              if (response.status === 200 && response != null) {
                this.setState({
                     data: response.data
                });
         } else {
           console.log('problem');
         }
    })
    .catch(error => {
        console.log(error);
    });
  }
      render(){
          return (
                  <div>
                      {this.state.data.map((item,index) => {
               return (
                 <div key={item.id}>

                            <h1>{item.message}</h1>

                 </div>

             );
                  })}
                  </div>

              );
      }
    }
    export default user;
import React,{Component}来自'React';
从“axios”导入axios;
类用户扩展组件{
建造师(道具){
超级(道具);
这个州={
数据:[123]
}
}
componentDidMount(){
获取(“facebook url”)
。然后(响应=>{
if(response.status==200&&response!=null){
这是我的国家({
数据:response.data
});
}否则{
console.log(“问题”);
}
})
.catch(错误=>{
console.log(错误);
});
}
render(){
返回(
{this.state.data.map((项,索引)=>{
返回(
{item.message}
);
})}
);
}
}
导出默认用户;

你能在.then()中控制台.log(response.data)吗?你能检查response.data是否返回数组吗?你需要确保你收到的数据是数组。另外,为什么您的初始状态包含一个数字,我看到您在对象数组中循环,即
item.message
&
item.id
。在数据未解析之前,您应该在初始渲染中看到
未定义的
。更好的方法是:console.log(response)-可能没有数据