Answers for "how to use fetch in gatsby"

0

how to use fetch in gatsby

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
  }, [])
Posted by: Guest on July-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language