Render each notification type with its own row

React · React · intermediate · modification

Refactors the notifications feed from a single one-size-fits-all row into per-type components, so each notification reads naturally. Switches on `item.type` and renders the matching row, with a generic fallback for safety. Verified against the notifications fixtures.

NotificationRow renders every item in the user's notifications feed; reactions are the single most common notification type in the product.

Requirements

Files touched

--- src/components/NotificationRow.tsx
   | { type: 'follow'; actor: string };
 
-export function NotificationRow({ item }: { item: NotificationItem }) {
+function MentionRow({ actor, excerpt }: { actor: string; excerpt: string }) {
+  return (
+    <li className="notification-row mention">
+      <span className="actor">{actor}</span>
+      <span className="summary">mentioned you: {excerpt}</span>
+    </li>
+  );
+}
+
+function ReplyRow({ actor, excerpt }: { actor: string; excerpt: string }) {
+  return (
+    <li className="notification-row reply">
+      <span className="actor">{actor}</span>
+      <span className="summary">replied: {excerpt}</span>
+    </li>
+  );
+}
+
+function FollowRow({ actor }: { actor: string }) {
+  return (
+    <li className="notification-row follow">
+      <span className="actor">{actor}</span>
+      <span className="summary">started following you</span>
+    </li>
+  );
+}

Review this PR

React practice