Skip to content

Instantly share code, notes, and snippets.

@omas-public
Created November 29, 2021 10:54
Show Gist options
  • Save omas-public/941f3e940e75d5483c2d1ca0f9fd0fb3 to your computer and use it in GitHub Desktop.
Save omas-public/941f3e940e75d5483c2d1ca0f9fd0fb3 to your computer and use it in GitHub Desktop.
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