react-springboot : 책 삭제하기

This commit is contained in:
haerong22
2021-02-08 21:15:38 +09:00
parent 3546a59734
commit 345dcdd9ff

View File

@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Button } from 'react-bootstrap';
const Detail = (props) => {
const id = props.match.params.id;
@@ -15,11 +16,25 @@ const Detail = (props) => {
.then((res) => {
setBook(res);
});
}, []);
}, [id]);
const deleteBook = () => {
fetch('http://localhost:8080/book/' + id, {
method: 'delete',
})
.then((res) => res.text())
.then((res) => {
res === 'ok' ? props.history.push('/') : alert('삭제실패');
});
};
return (
<div>
<h1> 상세보기</h1>
<Button variant="warning">수정</Button>{' '}
<Button variant="danger" onClick={deleteBook}>
삭제
</Button>
<hr />
<h3>{book.author}</h3>
<h1>{book.title}</h1>