Created
September 23, 2022 21:32
-
-
Save heyMP/9dc589f3c7700097e7259881a9f03e82 to your computer and use it in GitHub Desktop.
React Fetch Data
This file contains 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 { useEffect } from "react"; | |
const App = ({ placeholder, entry }) => { | |
const [categories, setCategories] = useState([]); | |
// useEffect(() => { | |
// fetch('https://google.com') | |
// .then(res => res.json()) | |
// .then(res => { | |
// setCategories(res.data.categories) | |
// }) | |
// .catch(err => console.log(error)) | |
// }, []); | |
useEffect(async () => { | |
const res = await fetch('https://google.com').then(res => res.json()) | |
setCategories(res.data.categories) | |
}, []); | |
return ( | |
<> | |
<ul> | |
{categories.map(category => ( | |
<li>{category}</li> | |
))} | |
</ul> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment