Lab 9: Responding to an Event
Objectives
- Add a button
- Handle the click event
Steps
Add a button
Open the file
src\projects\ProjectCard.tsxAdd an edit button to the
ProjectCardusing theHTMLsnippet 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
HTMLto make it validJSXsrc\projects\ProjectCard.tsx...<p>Budget...</p><button className=" bordered"><span className="icon-edit "></span>Edit</button>Verify the button displays in your browser.

Handle the click event
Add a
handleEditClickevent handler toProjectCardthat takes aprojectas an argument and logs it to theconsole.src\projects\ProjectCard.tsxfunction ProjectCard(props: ProjectCardProps) {const { project } = props;+ const handleEditClick = (projectBeingEdited: Project) => {+ 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
handleEditClickevent handler.src\projects\ProjectCard.tsxfunction ProjectCard(props: ProjectCardProps) {const { project } = props;const handleEditClick = (projectBeingEdited: Project) => {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><buttonclassName=" bordered"+ onClick={() => {+ handleEditClick(project);+ }}><span className="icon-edit "></span>Edit</button></section></div>);}
3) 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(F12orfn+F12on laptop).Click the edit button.
Verify the project is logged to the Chrome DevTools
console.