-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookShow.js
42 lines (35 loc) · 1015 Bytes
/
BookShow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useState } from 'react';
import BookEdit from './BookEdit';
import useBooksContext from '../hooks/use-books-context';
function BookShow({ book }) {
const [showEdit, setShowEdit] = useState(false);
const { deleteBookById } = useBooksContext();
const handleDeleteClick = () => {
deleteBookById(book.id);
};
const handleEditClick = () => {
setShowEdit(!showEdit);
};
const handleSubmit = () => {
setShowEdit(false);
};
let content = <h3>{book.title}</h3>;
if (showEdit) {
content = <BookEdit onSubmit={handleSubmit} book={book} />;
}
return (
<div className="book-show">
<img alt="books" src={`https://picsum.photos/seed/${book.id}/300/200`} />
<div>{content}</div>
<div className="actions">
<button className="edit" onClick={handleEditClick}>
Edit
</button>
<button className="delete" onClick={handleDeleteClick}>
Delete
</button>
</div>
</div>
);
}
export default BookShow;