This tutorial repo is a small, self-contained exercise for beginners learning React fundamentals: components, state, event handlers, and conditional rendering.
This is an intentionally simplified version of the app with comments and placeholders so students can implement the interactive parts themselves.
Goals
- Understand what a React component is.
- Add local state with
useState. - Handle DOM events (click, keyboard) in React.
- Conditionally render content based on component state.
- Make small, testable changes and run the dev server.
What you'll work with
src/App.jsx— the page that defines the topic list and contains static placeholders (cards). Replace the placeholder cards with your interactiveTopicCardcomponent.src/TopicCard.jsx— the card component (tutorial version). It currently displays static content and contains comments that point where to add state and event handlers.src/App.css— styles for the 3×2 square grid and card visuals.
- Copy this repo's link: code => clone => copy HTTPS
- Go to your VScode and open clone git repository (or use the terminal-- search how to do that! that's the beauty of SWE)
- Start your repo
- Create a new branch: git checkout -b "your-name"
- Start working!
Exercise (step-by-step)
- Start the dev server from the terminal:
npm install
npm run dev-
Open
src/TopicCard.jsxand read the comments. Try to implement the following:- Import
useStatefrom React. - Add a
const [showValue, setShowValue] = useState(false)line. - Add an
onClickhandler to the root.topic-cardelement that togglesshowValue. - Add keyboard handling so Enter and Space also toggle state (accessibility).
- Replace the static rendering so when
showValueis false the card shows thetopicname, and when true it shows thevalue(forFaceshow an<img>).
- Import
-
Replace the inline static cards in
src/App.jsx(the placeholder<div class="topic-card">elements) with theTopicCardcomponent
Example of the final usage in App.jsx:
<TopicCard key={t.topic} topic={t.topic} value={t.value} />- Try clicking and keyboard-operating the cards in the browser to confirm the behavior.
Hints
- The
Facetopic'svaluecontains a URL; use an<img src={value} />when showing it. - Use
role="button"andtabIndex={0}on the card element to make it keyboard-focusable. - Use
aria-pressed={showValue}to reflect toggle state to assistive tech.
Enjoy building— and ask if you get stuck on any of the steps!