TeachingW2-states/src/Gallery.jsx
Jeannette Chin f84dad4bf6 first commit
2024-09-30 18:22:25 +01:00

29 lines
642 B
JavaScript

import { useState } from "react";
import { sculptureList } from "./data.js";
const Gallery = () => {
const [index, setIndex] = useState(0);
const handleClick = () => {
// index = index + 1;
setIndex(index + 1);
};
let sculpture = sculptureList[index];
return (
<section>
<button onClick={handleClick}>Next</button>
<h2>
<i>{sculpture.name} </i> by {sculpture.description}{" "}
</h2>
<h3>
{index + 1} of {sculptureList.length}
</h3>
<img src={sculpture.url} alt={sculpture.alt} />
<p>{sculpture.description}</p>
</section>
);
};
export default Gallery;