data.json----------------------------------
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati exc.
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor.
App.js
import {useEffect, useState } from 'react';
const App =() =>{
const [dataList, setDataList] = useState([]);
useEffect(()=>{
fetch('http://localhost:3000/data.json')
.then(response => response.json())
.then(data => setDataList(data));
},[]);
return(
<div>
{dataList && dataList.map((team)=>{
return (
<>
<div key={team.id}>
<p>{team.id}</p>
<p>{team.title}</p>
</div>
</>
)})}
</div>
)
}
export default App;
No comments:
Post a Comment