Lab 8: More Reusable Components
Objectives
- Create another reusable component
- Render the reusable component
Steps
Create another reusable component
- Create the file - src\projects\ProjectCard.jsx.
- Implement a - ProjectCardas a function (not class) component that meets the following specifications:- Takes a projectobject as aprop.
- Cut the <div className="card">...</div>from theProjectListcomponent and use it as the JSX for theProjectCardcomponent.
- Add a function to format the description to 60 characters and call it when rendering the description.
 - src\projects\ProjectCard.jsx- import { Project } from './Project';
 import PropTypes from 'prop-types';
 function formatDescription(description) {
 return description.substring(0, 60) + '...';
 }
 function ProjectCard(props) {
 const { project } = props;
 return (
 <div className="card">
 <img src={project.imageUrl} alt={project.name} />
 <section className="section dark">
 <h5 className="strong">
 <strong>{project.name}</strong>
 </h5>
 <p>{formatDescription(project.description)}</p>
 <p>Budget : {project.budget.toLocaleString()}</p>
 </section>
 </div>
 );
 }
 ProjectCard.propTypes = {
 project: PropTypes.instanceOf(Project).isRequired,
 };
 export default ProjectCard;
- Takes a 
Render the reusable component
- Open the file - src\projects\ProjectList.jsx.
- Render the - ProjectCardcomponent passing it the- projectas a- prop.- src\projects\ProjectList.jsx- import PropTypes from 'prop-types';
 import { Project } from './Project';
 + import ProjectCard from './ProjectCard';
 function ProjectList ({ projects }) {
 const items = projects.map(project => (
 <div key={project.id} className="cols-sm">
 - <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>
 - </section>
 - </div>
 + <ProjectCard project={project} />
 </div>
 ));
 return <div className="row">{items}</div>;
 }
 ProjectList.propTypes = {
 projects: PropTypes.arrayOf(PropTypes.instanceOf(Project)).isRequired
 };
 export default ProjectList;
- Verify the project data displays correctly (it should still look the same as it did in the last lab except for the ... after the description) in the browser. 