react-springboot : 책 삭제하기
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { Button } from 'react-bootstrap';
|
||||||
|
|
||||||
const Detail = (props) => {
|
const Detail = (props) => {
|
||||||
const id = props.match.params.id;
|
const id = props.match.params.id;
|
||||||
@@ -15,11 +16,25 @@ const Detail = (props) => {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
setBook(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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>책 상세보기</h1>
|
<h1>책 상세보기</h1>
|
||||||
|
<Button variant="warning">수정</Button>{' '}
|
||||||
|
<Button variant="danger" onClick={deleteBook}>
|
||||||
|
삭제
|
||||||
|
</Button>
|
||||||
<hr />
|
<hr />
|
||||||
<h3>{book.author}</h3>
|
<h3>{book.author}</h3>
|
||||||
<h1>{book.title}</h1>
|
<h1>{book.title}</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user