Skip to content

Instantly share code, notes, and snippets.

@raflyfahrezi
Last active May 25, 2021 22:42
Show Gist options
  • Save raflyfahrezi/fa11575d993c008b243667ce37f081fb to your computer and use it in GitHub Desktop.
Save raflyfahrezi/fa11575d993c008b243667ce37f081fb to your computer and use it in GitHub Desktop.
fetching data in useEffect
import React, { useEffect, useState } from 'react'
import axios from 'axios'
const index = () => {
const [data, setData] = useState([])
useEffect(async () => {
const response = await axios.get('...some API path...')
setData(response.data)
}, [])
return (
<div>...</div>
)
}
export default index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment