Last active
May 25, 2021 22:42
-
-
Save raflyfahrezi/fa11575d993c008b243667ce37f081fb to your computer and use it in GitHub Desktop.
fetching data in useEffect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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