Created
November 23, 2021 18:41
-
-
Save PaulieScanlon/20066cbaa38ca79b2d36f83670bb4316 to your computer and use it in GitHub Desktop.
client side data with fetch
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 React, { useEffect, useState } from 'react'; | |
const Page = () => { | |
const [response, setResponse] = useState(false); | |
useEffect(() => { | |
const getData = async () => { | |
const response = await fetch( | |
'https://api.oceandrivers.com/api/ODWeather' | |
); | |
const data = await response.json(); | |
setResponse(data.apis); | |
}; | |
getData(); | |
}, []); | |
return ( | |
<main> | |
{response ? ( | |
<ul> | |
{response.map((item, index) => { | |
const { operations } = item; | |
return <li key={index}>{operations[0].notes}</li>; | |
})} | |
</ul> | |
) : ( | |
<div>Loading...</div> | |
)} | |
</main> | |
); | |
}; | |
export default Page; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment