Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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 使用github api v3获取的正确方法?_Reactjs_Fetch_Github Api - Fatal编程技术网

Reactjs 使用github api v3获取的正确方法?

Reactjs 使用github api v3获取的正确方法?,reactjs,fetch,github-api,Reactjs,Fetch,Github Api,我想映射回购协议的所有发行标题,并将它们呈现给react组件中的li。我已经能够使用octokat库仅提取问题标题,但不幸的是,该库不能很好地处理我正在进行的其他一些内容。另外,我相信我可以用es6和FetchAPI来实现这一点 原职: 在GithubAPI中使用es6 fetch/promises的信息查找方面花费了很长时间。我正试图获取回购的问题,但我显然错过了一些东西。。。我已经使用了一些不同的库来尝试并实现这一点,但我只想使用fetch 更新:现在我的新目标仅仅是控制台。记录标题。。。婴

我想映射回购协议的所有发行标题,并将它们呈现给react组件中的li。我已经能够使用octokat库仅提取问题标题,但不幸的是,该库不能很好地处理我正在进行的其他一些内容。另外,我相信我可以用es6和FetchAPI来实现这一点

原职:

在GithubAPI中使用es6 fetch/promises的信息查找方面花费了很长时间。我正试图获取回购的问题,但我显然错过了一些东西。。。我已经使用了一些不同的库来尝试并实现这一点,但我只想使用fetch

更新:现在我的新目标仅仅是控制台。记录标题。。。婴儿步

import React from "react";

export default class extends React.Component {
  constructor() {
    super()
    this.state = {
      issues: []
    }
  }
  componentWillMount() {
    // let issueArry = []
    const url = "https://api.github.com/repos/fightplights/chode-stream/issues"
    fetch(url)
      .then(response => response) // i've tried with and without .json()
      .then(body => console.log(body))
      // this logs the same response

  }
  render() {
    return (
      <div>
        <ul>
          {here i will map this.state.issues (once i can get them =))}
        </ul>
      </div>
    )
  }
}
但是,当我在下一次会议上作出回应时 .then(数据=>console.log(数据)) 它是未定义的。。。
我已经尝试返回第一个response=>response.json()(正如andy所建议的),但它已经是json了。。。我错了吗?

您需要从响应体读取JSON,您试图呈现的是完整的响应体

因此:

response.json()
返回一个承诺,因此您可以
。然后
返回它,返回值(
data
)将是您要查找的JS对象/数组。

您的浏览器devtools控制台显示什么错误消息?或者发生了什么或没有发生什么与你期望的不同?请使用编辑/更新您的问题,以包括可能未将响应设置为json的信息?我是否可以传递响应:.then(response).then()?您的方法仍有错误。它告诉我data.map()不是一个函数。我使用您的方法更新了我的示例。在dev工具中检查网络请求并查看响应。也许这是一个没有内容的200。bodyUsed的事实是假的,这是可疑的。我同意!我可能不小心将我的API令牌推到gh并将其吊销。我需要做一些挖掘。。。
Response { 
  type: "cors", 
  url: "https://api.github.com/repos/fightp…", 
  redirected: false, 
  status: 200, 
  ok: true, 
  statusText: "OK", 
  headers: Headers, 
  bodyUsed: false 
}
fetch(url)
  .then(response => response.json())
  .then(data => data.map(...)