Created
November 20, 2021 03:47
-
-
Save matthewholliday/9535dc70ddaef9f1de10eedfc97de47c to your computer and use it in GitHub Desktop.
Fetch data from API using promises 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(){ | |
fetch('http://localhost:8080/test').then( | |
response => { response.json(); } | |
).then( | |
response => { setTestData(response); } | |
); | |
} | |
setData(); | |
},[]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment