- Add a button
- Handle the click event
-
Open the file
src\projects\ProjectCard.js
-
Add an edit button to the
ProjectCard
using theHTML
snippet below.<!-- place this below the <p>Budget: ...</p> --> <button class="bordered"> <span class="icon-edit "></span> Edit </button>
Remember you will need to change some things about the
HTML
to make it validJSX
... <p> Budget... <button className=" bordered"> <span className="icon-edit "></span> Edit </button> </p>
-
Verify the button displays in your browser.
-
Add a
handleEditClick
event handler toProjectCard
that takes aproject
as an argument and logs it to theconsole
.function ProjectCard(props) { const { project } = props; + const handleEditClick = (projectBeingEdited) => { + console.log(projectBeingEdited); + }; return ( <div className="card"> <img src={project.imageUrl} alt={project.name} /> <section className="section dark"> <h5 className="strong"> <strong>{project.name}</strong> </h5> <p>{project.description}</p> <p>Budget : {project.budget.toLocaleString()}</p> <button className=" bordered"> <span className="icon-edit "></span> Edit </button> </section> </div> ); }
-
Wire up the click event of the edit button to the
handleEditClick
event handler.function ProjectCard(props) { const { project } = props; const handleEditClick = (projectBeingEdited) => { console.log(projectBeingEdited); }; return ( <div className="card"> <img src={project.imageUrl} alt={project.name} /> <section className="section dark"> <h5 className="strong"> <strong>{project.name}</strong> </h5> <p>{project.description}</p> <p>Budget : {project.budget.toLocaleString()}</p> <button className=" bordered" + onClick={() => { + handleEditClick(project); + }} > <span className="icon-edit "></span> Edit </button> </section> </div> ); }
-
Verify the application is working by following these steps:
- Open the application in your browser and refresh the page.
- Open the Chrome DevTools to the
console
(F12
orfn+F12
on laptop). - Click the edit button.
- Verify the project is logged to the Chrome DevTools
console
.