显示API数据

时间:2018-12-18 20:19:41

标签: javascript reactjs github github-api

我正在尝试从GIT API渲染不同的数据,并且目前无法评估我的问题是什么。我无法显示数据。我所能做的就是在本地主机的“元素”标签中查看它。我路由不正确吗?如果没有,可能是什么问题?

 import React, { Component } from 'react';

const urlForUsername = username =>
  `https://github.com/api/v3/users/${username}/events`;
   class AssociateIdentification extends Component {
   constructor(props) {
    super(props);
    this.state = {
       requestFailed: false
    };
  }
   componentDidMount() {
    fetch(urlForUsername(this.props.username))
      .then(response => {
        if (!response.ok) {
          throw Error('Network requst failed');
        }
         return response;
      })
      .then(d => d.json())
      .then(d => {
        this.setState({
          githubData: d
        });
      }, () => {
        this.setState({
          requestFailed: true
        });
      } );
   }

  render() {

    if (!this.state.githubData) return <p> Loading...</p>;
    if (this.state.requestFailed) return <p>Failed!</p>;

    return (
      <div>

这就是我认为可能不对的地方,它的路由方式并不完全确定。

 {this.state.githubData.actor}  {this.props.username} 
      </div>
        );
      }
    }

 export default (AssociateIdentification);

任何帮助!谢谢!

这就是我收到的注释建议控制台日志

Promise {<resolved>: Array(6)}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Array(6)
 0: {id: "11174255", type: "PushEvent", actor: {…}, repo: {…}, payload: {…}, …}
length: 6
__proto__: Array(0)

0 个答案:

没有答案