//App.js
//https://jsonplaceholder.typicode.com/comments
const getData = async () => {
const res = await fetch(
"https://jsonplaceholder.typicode.com/comments"
).then((res) => res.json());
const initData = res.slice(0,20).map((it)=>{
return{
author: it.email,
content : it.body,
//Math.random은 항상 소수점 반환하기 때문에 Math.floor 이용해 정수로 반환함
emotion : Math.floor(Math.random() * 5) + 1,
created_date : new Date().getTime(),
//지금은 return이 바로 되기때문에 기존처럼 id +1 방식은 불가능함
id : dataId.current++
}
})
setData(initData);
}
재밌다..!