Frontend School

Build a Basic Chat Message Display

Machine Coding
easy

Build a Basic Chat Message Display

Easy
React
UI
Component
Chat
Styling

Overview

In modern applications, real-time communication is crucial. A well-designed chat interface is fundamental to user engagement. This problem focuses on building the core message display component of a chat application, ensuring messages are clearly presented and distinguished between senders. This exercise will test your ability to structure UI components, manage data display, and apply styling effectively.

What you need to do / Task

Your task is to build a React component that displays a list of chat messages based on provided mock data.

  1. Render Message List: Display all messages from the mockMessages array in chronological order.
  2. Display Message Details: For each message, clearly show:
    • The sender's name.
    • The message content.
    • A formatted timestamp (e.g., "HH:MM AM/PM").
  3. Distinguish Senders: Visually differentiate messages sent by the currentUser from messages sent by other participants.

UI/UX expectations

  • Layout: Messages should be stacked vertically, with each message occupying its own row.
  • Alignment: Messages from the currentUser should be right-aligned within their container. Messages from other users should be left-aligned.
  • Styling:
    • Messages from the currentUser should have a distinct background color (e.g., light blue) and text color.
    • Messages from other users should have a different background color (e.g., light gray) and text color.
    • Sender name, message content, and timestamp should be clearly visible and legible.
  • Readability: Ensure sufficient padding and margin for messages to avoid a cramped appearance.

Acceptance criteria

  • All messages from mockMessages are rendered on the screen.
  • Each message displays the senderName, content, and a formatted timestamp.
  • Messages sent by the currentUser (ID matching currentUserId) are right-aligned.
  • Messages sent by other users are left-aligned.
  • Messages from the currentUser have a visually distinct background color.
  • Messages from other users have a different distinct background color.
  • The overall layout is clean and readable.

Constraints

Constraints & assumptions

  • You must use React for building the UI.
  • All data required is provided in the mockMessages array and currentUserId constant.
  • Focus purely on rendering the message list; do not implement message input, sending, or real-time features.
  • No external libraries are strictly required beyond React itself. You may use standard browser APIs for date formatting.
  • The application will run in a standard web browser environment.

Out of scope

  • Implementing a message input field or send button.
  • Handling message scrolling or auto-scroll to the latest message.
  • Displaying user avatars or complex user profiles.
  • Advanced styling for responsiveness across different screen sizes beyond basic layout.
  • Any backend integration or API calls.

What interviewers evaluate

  • Correctness: Does the solution correctly render all messages and apply the specified styling rules based on the sender?
  • Component Structure: Is the React component well-organized, with clear separation of concerns, and does it use props effectively?
  • Styling Implementation: How effectively are CSS or other styling methods used to achieve the desired UI/UX?
  • Code Quality: Is the code clean, readable, maintainable, and idiomatic React?

Loading editor...