📜  如何在 gatsby 中使用 fetch - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:23.309000             🧑  作者: Mango

代码示例1
const [starsCount, setStarsCount] = useState(0)
  useEffect(() => {
    // get data from GitHub api
    fetch(`https://api.github.com/repos/gatsbyjs/gatsby`)
      .then(response => response.json()) // parse JSON from request
      .then(resultData => {
        setStarsCount(resultData.stargazers_count)
      }) // set data for the number of stars
  }, [])