Module 31: Introduction to React
Project structure and your first screen
🏠The everyday picture
A well-organised toolbox: screwdrivers in one tray, spanners in another. You find things fast, and so does anyone who borrows it.
📘What it really is
- A common structure for a small React app:
src/
components/ reusable pieces (buttons, cards)
pages/ whole screens (Dashboard, EnquiryDetail)
types.ts shared TypeScript types
data.ts sample data, until there's a backend
App.tsx
main.tsx
- Shared types work exactly as in Module 28:
export interface Enquiry {
id: string;
name: string;
email: string;
subject: string;
status: "new" | "in-progress" | "closed";
createdAt: string;
}
-
Styling options: one global CSS file, a CSS file per component, CSS Modules (
Card.module.css, class names that can't clash), or utility libraries like Tailwind. Start simple; your Level 2 CSS skills all apply. -
Developer tools: install the React Developer Tools browser extension. Its Components tab shows your component tree and each component's data.
🖱️Try it
Set up the folders above. Add the Enquiry type and an array of five sample enquiries in data.ts. Create
pages/Dashboard.tsx that shows the header, a heading "Open enquiries", and the cards. Style it with your Level 2
CSS, making sure it works on a phone. Look at the tree in React Developer Tools.
✅Quick check
What's the difference between components/ and pages/?
Show the answer
Components are reusable pieces; pages are whole screens built from them.
Where should the Enquiry type live, and why?
Show the answer
In a shared types.ts, so every component uses the same definition.
