Training Grounds
Notification Badges Rerender on Every Typed CharacterBlue Belt
+25 Ki
Description

A compose box shows a character count as the user types a draft message, alongside a notification badges panel listing alert categories that never change. Typing in the draft field should have no effect on the badges panel.

Anomaly

Type a single character into the compose box - the badges panel's render count climbs even though the categories displayed never change.

Constraint
Do not remove React.memo from NotificationBadges
Do not change what the textarea or character count does
Hint

categories looks like the same three values on every render - but does JavaScript agree that it's the same array?

Consult the SenseiOnly for those truly stuck · Flip to reveal

categories looks like the same three values on every render - but does JavaScript agree that it's the same array?

Loading editor…
Correct Solution
Loading...

Why this fixes it

["mentions", "replies", "likes"] is written directly inline in the JSX passed to NotificationBadges, which means a brand new array is constructed at a new memory address every time ComposeBox renders, even though its contents never change. React.memo's prop comparison uses reference equality, and two arrays with identical contents are never === to each other, so the comparison fails on every keystroke and NotificationBadges re-renders regardless of the memo wrapper. Moving the array to a module-level constant gives it a single permanent reference that exists once, outside the component function, so every render passes the exact same array reference and the memo comparison correctly finds no change.

Expected OutputGoal State
Your OutputLive