Last active
February 14, 2023 04:45
-
-
Save omas-public/0abf242631fd194b5ee5e2f30312b25c 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 React, { useState, useEffect } from 'react' | |
import fetchData from './api/fetchData' | |
const URI = 'https://jsonplaceholder.typicode.com/users' | |
const Main = props => { | |
const [data, setData] = useState(null) | |
useEffect(() => { | |
const fetchAPI = async () => { | |
const data = await fetchData(URI) | |
setData(data) | |
} | |
fetchAPI() | |
}, []) | |
if (!data) return null | |
return ( | |
<> | |
<h1>hello</h1> | |
<ul> | |
{ | |
data.map(user => <li key={user.id}>{user.name}</li>) | |
} | |
</ul> | |
</> | |
) | |
} | |
export default Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment