Loading Depth Study
Preparing your workspace
Props are read-only inputs that a component receives from its parent.
Props allow components to become reusable because the same component can display different data. A parent passes props using JSX attributes, and the child receives them as an object. Props should be treated as read-only by the receiving component. If a child needs to change information, it usually communicates the event back to the parent through a callback function passed as a prop. Props can contain strings, numbers, booleans, objects, arrays, functions, and even React elements.
One CourseCard component can display hundreds of different courses by receiving title, instructor, level, and progress as props.
function CourseCard({ title, level, progress }) {
return (
<article>
<h2>{title}</h2>
<p>Level: {level}</p>
<p>Progress: {progress}%</p>
</article>
);
}
export default function App() {
return (
<CourseCard
title="React Fundamentals"
level="Beginner"
progress={65}
/>
);
}The course card displays the React Fundamentals course with beginner level and 65% progress.