Created
November 20, 2021 03:43
-
-
Save matthewholliday/2a417d7c69867ab79046cd6183dab041 to your computer and use it in GitHub Desktop.
Use fetch with await/async in react
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
const [testData,setTestData] = useState({message : "abc"}); | |
useEffect(() => { | |
async function setData(){ | |
const response = await fetch('http://localhost:8080/test'); | |
const parsedData = await response.json(); | |
setTestData(parsedData); | |
setData(); | |
},[]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment