Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

useeffect async not working

function Example() {
  const [data, dataSet] = useState<any>(null)

  useEffect(() => {
    async function fetchMyAPI() { // make a new async function with a function name
      let response = await fetch('api/data')
      response = await response.json()
      dataSet(response)
    }

    fetchMyAPI() // call the unction inside the useEffect()
  }, [])

  return <div>{JSON.stringify(data)}</div>
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript log error without traceback 
Javascript :: mongodb pull multiple 
Javascript :: how to exclude a specefic tagname from a javascript query search 
Javascript :: angular int to string 
Javascript :: settimeout arrow function javascript 
Javascript :: save in json file js 
Javascript :: loop json jquery 
Javascript :: js date year 
Javascript :: styled of styled component not working in nextjs 
Javascript :: slick on init 
Javascript :: how to take value of input using getelementsbyname in javascript 
Javascript :: datetimepicker set value 
Javascript :: angular mat select open programmatically 
Javascript :: javascript unique array of objects by property 
Javascript :: split words in javascript 
Javascript :: jquery first child 
Javascript :: javascript regex vowel 
Javascript :: find quotient in javascript 
Javascript :: javascript execute code on page load 
Javascript :: javascript get name of element 
Javascript :: javascript only allow show first few characters from a string 
Javascript :: check if json obj exists 
Javascript :: display image base64 in REACT NATIVE 
Javascript :: check either define or undefined in javascript 
Javascript :: network response timed out expo 
Javascript :: jsx if block 
Javascript :: create label dynamically in javascript 
Javascript :: jquery validation plugin 
Javascript :: how to create uuid in javascript 
Javascript :: nodejs create buffer from string 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =