Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
  }, [])
Comment

PREVIOUS NEXT
Code Example
Javascript :: express-rate-limit nodejs 
Javascript :: html get input box value by element id 
Javascript :: document.getanimation 
Javascript :: js get last n elements of array 
Javascript :: String operators in JavaScript 
Javascript :: javascript yyyy-mm-dd to mm-dd-yyyy human readable format 
Javascript :: max value javascript 
Javascript :: sum float values in jquery 
Javascript :: how to loop over an array in js 
Javascript :: find longest palindrome javascript algorithm 
Javascript :: validate password in nodejs 
Javascript :: switch window 
Javascript :: why we use mongoose 
Javascript :: sort array based on multiple columns javascript 
Javascript :: double click on element using javascript 
Javascript :: svelte wait 
Javascript :: format phone number javascript 
Javascript :: is odd javascript 
Javascript :: array.contains javascript 
Javascript :: Redirect user when JavaScript is disabled with noscript 
Javascript :: javascript Assigning to a non-writable property is not allowe 
Javascript :: apply() js 
Javascript :: find second smallest number in array javascript using for loop 
Javascript :: how to assign onEdit to specigfic tab 
Javascript :: jquery append text for 5 seconds 
Javascript :: es6 closures 
Javascript :: change profile photo with javascript 
Javascript :: expo location background example 
Javascript :: import json file into javascript 
Javascript :: convert svg to react component 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =