Skip to content

Commit 8753960

Browse files
Added basic events and es6 modules
1 parent 1c7230a commit 8753960

File tree

3 files changed

+56
-31
lines changed

3 files changed

+56
-31
lines changed

src/Book.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from "react";
2+
3+
const displayBookAuthor = (author) => {
4+
alert(author);
5+
};
6+
7+
const displayBookTitle = (title) => {
8+
alert(title);
9+
};
10+
11+
const Book = (props) => {
12+
// console.log(props);
13+
const { title, image, author, alt } = props;
14+
return (
15+
<article className="book">
16+
<div className="wrapper">
17+
<img
18+
src={image}
19+
alt={alt}
20+
width={200}
21+
height={100}
22+
onMouseOver={() => displayBookTitle(title)}
23+
/>
24+
</div>
25+
<h1>{title}</h1>
26+
<h4>{author}</h4>
27+
<button type="button" onClick={() => console.log(title)}>
28+
Show title
29+
</button>
30+
<button type="button" onClick={() => displayBookAuthor(author)}>
31+
Show author
32+
</button>
33+
</article>
34+
);
35+
};
36+
37+
export default Book;

src/books_data.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const books = [
2+
{
3+
id: 1,
4+
image: "https://picsum.photos/200/100",
5+
alt: "Book cover",
6+
title: "The Way to The Jungle.",
7+
author: "Michael Boateng",
8+
},
9+
{
10+
id: 2,
11+
image: "https://picsum.photos/200/100",
12+
alt: "Book cover",
13+
title: "The Way to Music",
14+
author: "Blue Ivy Carter",
15+
},
16+
];

src/index.js

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,9 @@ import ReactDOM from "react-dom/client";
44
// CSS
55
import "./index.css";
66

7-
// Variables
8-
const books = [
9-
{
10-
id: 1,
11-
image: "https://picsum.photos/200/100",
12-
alt: "Book cover",
13-
title: "The Way to The Jungle.",
14-
author: "Michael Boateng",
15-
},
16-
{
17-
id: 2,
18-
image: "https://picsum.photos/200/100",
19-
alt: "Book cover",
20-
title: "The Way to Music",
21-
author: "Blue Ivy Carter",
22-
},
23-
];
7+
// JS
8+
import Book from "./Book";
9+
import { books } from "./books_data";
2410

2511
function Booklist() {
2612
return (
@@ -33,18 +19,4 @@ function Booklist() {
3319
);
3420
}
3521

36-
const Book = (props) => {
37-
console.log(props);
38-
const { title, image, author, alt } = props;
39-
return (
40-
<article className="book">
41-
<div className="wrapper">
42-
<img src={image} alt={alt} width={200} height={100} />
43-
</div>
44-
<h1>{title}</h1>
45-
<h4>{author}</h4>
46-
</article>
47-
);
48-
};
49-
5022
ReactDOM.createRoot(document.getElementById("root")).render(<Booklist />);

0 commit comments

Comments
 (0)