안녕하세요?
제일 마지막 강의인 serverActions에 대해서 관심이 많이 생겼습니다.
설명해 주신거까지는 대충 알겠는데,
우리가 지금까지 만든 것 중에서 delete와 관련된 것도 serverActions으로 만들 수 있나요?
현재는 아래와 같이 ListItems.js 파일에 fetch 이용해서 만들어놨는데, 도저히 serverActions으로 만들 수 있는 방법을 모르겠네요.
<span style={{cursor:"pointer"}} onClick={(e) => { fetch('/api/delete', {method : 'POST', body : item._id})
.then((r)=>{return r.json()})
// console.log(res);
.then((response)=>{
// console.log(response);
if (response == '삭제완료'){
e.target.parentElement.style.opacity = 0;
setTimeout(()=>{
e.target.parentElement.style.display = "none";
},1000)
}
})
}}>삭제</span>