Build a bell icon with an unread-count badge.
Skip to solutionKEEP THE
easyMachine Coding
Build a Notification Badge
1.2k views
01
Understand the problem
ReactUIBadge
02
Attempt it yourself
Sketch your approach before reading the solution — that's what interviews test.
Nudge consolestandby
Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.
03
Study the solution
Solve in
This tutorial will guide you through building a Notification Badge component in React.
Mental Model
The core idea is to have a parent NotificationBadge component that renders a bell icon and conditionally displays a smaller badge component with the unread count. The count will be managed via React state and upda
Solution ready — 2 min read
Classified // press E to declassify
04
React solution
Complete solutionRun Playground
import React, { useState } from 'react';
import NotificationBadge from './src/NotificationBadge';
export default function App() {
const [unreadCount, setUnreadCount] = useState(0);
const incrementCount = () => {
setUnreadCount(prevCount => prevCount + 1);
};
const resetCount = () => {
setUnreadCount(0);
};
return (
<div style={{ fontFamily: 'sans-serif', textAlign: 'center', padding: '20px' }}>
<h1>Notification Badge Demo</h1>
<NotificationBadge count={unreadCount} />
<p>Current unread count: {unreadCount}</p>
<button onClick={incrementCount} style={{ margin: '5px', padding: '10px 15px' }}>
Add Notification
</button>
<button onClick={resetCount} style={{ margin: '5px', padding: '10px 15px' }}>
Clear Notifications
</button>
</div>
);
}05
Join the discussion
Discussion (0)
Sign in to join the discussion.
No responses yet. Be the first to share what you think.
Transmission complete // awaiting log
KEEP THE
STREAK ALIVE.
Dossier 1 of 87 decoded in the Frontend Machine Coding track. One more won't hurt.