캡틴 판교님 글 참고하여 공부하였습니다.
// 게시물 삭제 => redux로 상태관리 안 하고 axios만 하면 꼭 get 해주기
// 타입 신경쓰기(uuid 안 쓰니 number로)
const deleteContent = async (contentId : number) => {
axios.delete(`http://localhost:3001/contentList/${contentId}`)
const { data } = await axios.get('http://localhost:3001/contentList')
setContentList(data)
}
// async / await로 axios 비동기를 적용한 사례
promise를 썼을 수도 있으나 가독성 등을 따졌을 때 훨씬 더 보기 좋았고 쓰기 편해서 사용했다.
async function logTodoTitle() {
try {
var user = await fetchUser();
if (user.id === 1) {
var todo = await fetchTodo();
console.log(todo.title);
// delectus aut autem
}
} catch (error) {
console.log(error);
}
}