Created
November 29, 2021 10:54
-
-
Save omas-public/941f3e940e75d5483c2d1ca0f9fd0fb3 to your computer and use it in GitHub Desktop.
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 { useEffect, useState } from 'react' | |
const SampleList = ({ values }) => ( | |
<ul> | |
{ | |
values.map(({ id, item }) => | |
<li key={id}>{item}</li> | |
) | |
} | |
</ul> | |
) | |
const fetchData = async (uri) => { | |
const data = await window.fetch(uri) | |
.then(res => res.json()) | |
.then(json => json.values) | |
return data | |
} | |
const App = props => { | |
const [values, setValues] = useState([]) | |
useEffect(() => ( | |
fetchData('http://localhost:3000/values.json') | |
.then(values => setValues(values)) | |
), []) | |
return ( | |
<> | |
<SampleList values={values} /> | |
</> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment