Answers for "async in useeffect"

0

async in useeffect

function myApp() {
  const [data, setdata] = useState()

  useEffect(() => {
    async function fetchMyAPI() {
      const response = await fetch('api/data')
      response = await response.json()
      setdata(response)
    }

    fetchMyAPI()
  }, [])
}
Posted by: Guest on June-05-2021
-1

async in useeffect

useEffect(() => {
    (async () => {
      const products = await api.index()
      setFilteredProducts(products)
      setProducts(products)
    })()
  }, [])
Posted by: Guest on May-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language