File tree Expand file tree Collapse file tree 3 files changed +56
-31
lines changed Expand file tree Collapse file tree 3 files changed +56
-31
lines changed Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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+ ] ;
Original file line number Diff line number Diff line change @@ -4,23 +4,9 @@ import ReactDOM from "react-dom/client";
44// CSS
55import "./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
2511function 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-
5022ReactDOM . createRoot ( document . getElementById ( "root" ) ) . render ( < Booklist /> ) ;
You can’t perform that action at this time.
0 commit comments