React_Labs_Chapters_01_04
zip26 files16 kBIn React labs: chapters 1–4
lab1-solution/5
src/4
components/6
CourseSummary.jsx1 kBLabOverview.jsx1 kBResourceItem.jsx1 kBResourceList.jsx1 kBSectionTitle.jsx1 kBWelcomeBanner.jsx1 kBlab1-template/5
index.html1 kBpackage.json1 kBREADME.md1 kBvite.config.js1 kBReact_Lab_Ch01-04_Student.md
React Lab 01 – Chapters 01–04 (Student Guide)
Goal
Apply JSX fundamentals, props, lists, and composition exactly as presented in chapters 01–04 to build a multi-section lab overview page.
Template Requirement
- Locate the provided
lab-templateReact + Vite project. - Duplicate the folder and rename it using the pattern
react-lab01-<yourname>. - Install dependencies with
npm installfrom inside the duplicated folder. - Do not rename or delete starter files. All new components should live under
src/components.
Predefined Styling
- Keep the stylesheet
src/styles/lab-theme.cssexactly as provided. - When you need new styles, add class names to your JSX and extend the CSS in a separate file (e.g.,
src/styles/extensions.css) that you import intoApp.jsx. - Use the existing utility classes (cards, layout, typography) to keep a consistent look.
Part 1 – JSX & Rendering (Chapter 01)
- Create a file
src/components/WelcomeBanner.jsx. - Export a function component that accepts props:
course,instructor,term, anddescription. - The component should return a single
<section>with:- Course title (from
courseprop), term (fromtermprop), instructor name (frominstructorprop) and description (fromdescriptionprop). - A welcome paragraph explaining the lab focus.
- At least one nested element (e.g.,
<strong>or<span>) to practice JSX nesting.
- Course title (from
- Import and render
WelcomeBannerinsidesrc/App.jsx, passing the required props as static values. - Verify that the component renders correctly before moving on.
- Stretch: Add a helper function inside the component that returns "صباح الخير" or "مساء الخير" based on the current hour (use plain JavaScript conditionals only). Display this greeting in the component.
Part 2 – Props & Component Hierarchy (Chapter 02)
- Create
src/components/CourseSummary.jsx. - Define props:
title,topics,duration,deliveryMode, and an optionalchildrenarea for extra notes. - In
App.jsx, pass static (hard-coded) values for these props—no state or external data yet. - Render
CourseSummaryimmediately afterWelcomeBanner. The summary should be wrapped in a card layout using the predefined CSS. - Add a footer note by wrapping additional JSX between the opening and closing tags of
CourseSummary(this will populateprops.children). The note should be passed as a child element (e.g.,<p className="note">...</p>). - Stretch: Provide a short static array (e.g., three bullet topics) as a prop and render it inline, separated by commas—no loops or dynamic updates in this stretch.
Part 3 – JSX Lists & Reusable Components (Chapter 03)
- Create
src/components/ResourceItem.jsxto display a resource title and description. - The component should accept props:
title,description, and an optionalisNew(boolean). - In
App.jsx, declare a constant arraylabResourceswith at least four objects ({ id, title, description }). Optionally, some objects can includeisNew: true. - Create
src/components/ResourceList.jsxthat accepts aresourcesprop (array). Inside, map over the resources array to render aResourceItemfor each entry. Supply thekeyprop using theidfrom each resource object. - Wrap the list in a
<section>with a title like "Lab Resources" and apply the predefined list styling classes. - Stretch: In
ResourceItem, add a small badge (e.g., "NEW") that appears only when theisNewprop istrue(use a ternary in JSX, not state).
Part 4 – Layout Composition (Chapter 04)
- Create
src/components/LabOverview.jsx. - Inside
LabOverview, compose the previous components in this order:WelcomeBanner, a pair ofCourseSummarycomponents (current lab and upcoming lab), and the resource list section (usingResourceList). - Accept props in
LabOverview:welcome(object withcourse,instructor,term,description),current(object withtitle,topics,duration,deliveryMode,note),upcoming(object with same structure ascurrent), andresources(array of resource objects). - Pass the appropriate props to each child component. For
CourseSummarycomponents, pass the data using spread operator ({...current}) and include thenoteas children (e.g.,<p className="note">{current.note}</p>). - In
App.jsx, importLabOverview, prepare the data objects, and render the overview as the only child inside<main>. - Apply the predefined layout class to arrange sections (e.g., two columns on wide screens).
- Stretch: Create a small reusable
SectionTitlecomponent insrc/componentsthat acceptstextand optionallevel(default "h2") props. Use it in at least two sections to standardize headings.
Deliverables
- A working React project built on the template with all components compiled successfully.
README.mdat the project root containing:- Setup steps you followed.
- Brief description of each component.
- Any stretch goals you completed.
- Optional reflection file
REFLECTION.mddescribing one challenge per part and how you solved it.
Submission Checklist
- Template duplicated and dependencies installed.
- All components placed under
src/components. - Styling uses the provided
lab-theme.cssplus optional extensions. -
LabOverviewrenders every required section without runtime warnings. - README completed and project runs with
npm run dev.
Good luck, and remember to stay within chapters 01–04—no hooks or advanced patterns yet!