🟨 React
Easy
🕐 1 story point

React: Extract Repeated UI into a Component

There’s a repeated UI notice block. Extract it into a reusable MessageCard component and use it in App instead of duplicating markup.

Alexander, React internship team lead

Clean code means fewer duplicates. Encapsulating repeating UI in a component makes changes and testing easier.

What To Do

  1. Create MessageCard with title and text props.
  2. Move the repeated markup into MessageCard.
  3. In App, replace the three blocks with three MessageCard instances.
  4. Add data-testid="message-card" to the root element.
💡 Hint
  • Component:
    function MessageCard({ title, text }) {
      return (
        <article className="notice" data-testid="message-card">
          <h3 className="notice__title">{title}</h3>
          <p className="notice__text">{text}</p>
        </article>
      );
    }
  • In App:
    <MessageCard title="Success" text="Operation completed" />
👀 Solution
import React from 'react';
import './styles.css';
 
export function MessageCard({ title, text }) {
  return (
    <article className="notice" data-testid="message-card">
      <h3 className="notice__title">{title}</h3>
      <p className="notice__text">{text}</p>
    </article>
  );
}
 
export default function App() {
  return (
    <main className="challenge-container">
      <section>
        <MessageCard title="Success" text="Operation completed" />
        <div style={{ marginTop: 16 }}>
          <MessageCard title="Warning" text="Please check input" />
        </div>
        <div style={{ marginTop: 16 }}>
          <MessageCard title="Error" text="Something went wrong" />
        </div>
      </section>
    </main>
  );
}

Why this works: The repeating UI is encapsulated; duplication is gone, readability improves, and changes are centralized.

🧑‍💻 It's not a bug! It's a feature!

The code editor is intentionally hidden on mobile.

Believe me, it's for the best: I am protecting you from the temptation to code in less-than-ideal conditions. A small screen and a virtual keyboard are not the best tools for a programmer.

📖 Now: Study the task, think through the solution. Act like a strategist.

💻 Later: Sit down at your computer, open the site, and implement all your ideas comfortably. Act like a code-jedi!